Skip to content

Commit eb5ae10

Browse files
authored
Merge pull request #7150 from Shopify/dlm-store-execute-canonicalize-store
Adjust store auth warning for non-canonical store domain
2 parents 2488015 + 3bbda17 commit eb5ae10

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

packages/cli/src/cli/services/store/auth.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ describe('store auth service', () => {
156156
).rejects.toThrow('OAuth callback state does not match the original request.')
157157
})
158158

159-
test('waitForStoreAuthCode rejects when callback store does not match', async () => {
159+
test('waitForStoreAuthCode rejects when callback store does not match and suggests the returned permanent domain', async () => {
160160
const port = await getAvailablePort()
161161
const params = callbackParams({shop: 'other-shop.myshopify.com'})
162162

@@ -172,7 +172,11 @@ describe('store auth service', () => {
172172
await response.text()
173173
},
174174
}),
175-
).rejects.toThrow('OAuth callback store does not match the requested store.')
175+
).rejects.toMatchObject({
176+
message: 'OAuth callback store does not match the requested store.',
177+
tryMessage:
178+
'Shopify returned other-shop.myshopify.com during authentication. Re-run shopify store auth --store other-shop.myshopify.com --scopes <comma-separated-scopes> using the permanent store domain instead of an alias or vanity domain.',
179+
})
176180
})
177181

178182
test('waitForStoreAuthCode rejects when Shopify returns an OAuth error', async () => {

packages/cli/src/cli/services/store/auth.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,22 +190,31 @@ export async function waitForStoreAuthCode({
190190

191191
const {searchParams} = requestUrl
192192

193-
const fail = (message: string) => {
193+
const fail = (message: string, tryMessage?: string) => {
194194
res.statusCode = 400
195195
res.setHeader('Content-Type', 'text/html')
196196
res.setHeader('Connection', 'close')
197-
res.once('finish', () => settleWithError(new AbortError(message)))
197+
res.once('finish', () => settleWithError(new AbortError(message, tryMessage)))
198198
res.end(renderAuthCallbackPage('Authentication failed', message))
199199
}
200200

201201
const returnedStore = searchParams.get('shop')
202202
outputDebug(outputContent`Received OAuth callback for shop ${outputToken.raw(returnedStore ?? 'unknown')}`)
203203

204-
if (!returnedStore || normalizeStoreFqdn(returnedStore) !== normalizedStore) {
204+
if (!returnedStore) {
205205
fail('OAuth callback store does not match the requested store.')
206206
return
207207
}
208208

209+
const normalizedReturnedStore = normalizeStoreFqdn(returnedStore)
210+
if (normalizedReturnedStore !== normalizedStore) {
211+
fail(
212+
'OAuth callback store does not match the requested store.',
213+
`Shopify returned ${normalizedReturnedStore} during authentication. Re-run ${outputToken.genericShellCommand(`shopify store auth --store ${normalizedReturnedStore} --scopes <comma-separated-scopes>`).value} using the permanent store domain instead of an alias or vanity domain.`,
214+
)
215+
return
216+
}
217+
209218
const returnedState = searchParams.get('state')
210219
if (!returnedState || !constantTimeEqual(returnedState, state)) {
211220
fail('OAuth callback state does not match the original request.')

0 commit comments

Comments
 (0)