Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/app/src/cli/utilities/app/app-url.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import {normalizeStoreFqdn} from '@shopify/cli-kit/node/context/fqdn'
import {normalizeStoreFqdn, storeAdminUrl} from '@shopify/cli-kit/node/context/fqdn'

export function buildAppURLForWeb(storeFqdn: string, apiKey: string) {
const normalizedFQDN = normalizeStoreFqdn(storeFqdn)
return `https://${normalizedFQDN}/admin/oauth/redirect_from_cli?client_id=${apiKey}`
const adminUrl = storeAdminUrl(normalizedFQDN)
return `https://${adminUrl}/admin/oauth/redirect_from_cli?client_id=${apiKey}`
}

export function buildAppURLForMobile(storeFqdn: string, apiKey: string) {
const normalizedFQDN = normalizeStoreFqdn(storeFqdn)
const hostUrl = `${normalizedFQDN}/admin/apps/${apiKey}`
const adminUrl = storeAdminUrl(normalizedFQDN)
const hostUrl = `${adminUrl}/admin/apps/${apiKey}`
const hostParam = Buffer.from(hostUrl).toString('base64').replace(/[=]/g, '')
return `https://${hostUrl}?shop=${normalizedFQDN}&host=${hostParam}`
}
20 changes: 16 additions & 4 deletions packages/cli-kit/src/public/node/context/fqdn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,20 @@ export function normalizeStoreFqdn(store: string): string {
}
const containDomain = (storeFqdn: string) =>
storeFqdn.endsWith('.myshopify.com') || storeFqdn.endsWith('shopify.io') || storeFqdn.endsWith('.shop.dev')
const normalizedFqdn = containDomain(storeFqdn) ? storeFqdn : addDomain(storeFqdn)
// Use dev-api domain for OAuth redirects in local environment
// See: https://github.com/Shopify/dev_server?tab=readme-ov-file#shop-redirects
return normalizedFqdn.replace('.my.shop.dev', '.dev-api.shop.dev')
return containDomain(storeFqdn) ? storeFqdn : addDomain(storeFqdn)
}

/**
* Convert a store FQDN to the admin URL pattern for local development.
* In local mode, transforms \{store\}.my.shop.dev to admin.shop.dev/store/\{store\}.
*
* @param storeFqdn - Normalized store FQDN.
* @returns Store admin URL base (without protocol or path).
*/
export function storeAdminUrl(storeFqdn: string): string {
if (serviceEnvironment() === 'local' && storeFqdn.endsWith('.my.shop.dev')) {
const storeName = storeFqdn.replace('.my.shop.dev', '')
return `admin.shop.dev/store/${storeName}`
}
return storeFqdn
}
Loading