Fix reauthentication after a preview store is claimed - #8349
Conversation
Assisted-By: devx/f6cd24e9-3d53-4ab0-9851-a3eb94f559e8
Assisted-By: devx/f6cd24e9-3d53-4ab0-9851-a3eb94f559e8
|
/snapit |
There was a problem hiding this comment.
Pull request overview
This PR fixes a recovery dead-end where a claimed preview store leaves behind a stale kind: 'preview' session that prevents the suggested recovery command (shopify store auth) from running. It updates the store info / admin transport recovery behavior to clear preview sessions once a 401/404 confirms the preview credential is invalid, so reauthentication can proceed.
Changes:
- Clear stored preview sessions on 401/404 from both the preview-store lookup path and Admin API paths, then surface the existing claimed-preview reauth guidance.
- Update unit tests to assert preview-session clearing behavior for
store infoandstore execute. - Add a local-storage regression test demonstrating that clearing the preview session unblocks
store auth, plus a patch changeset.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/store/src/cli/services/store/info/index.ts | Clears preview sessions on 401/404 from preview-store lookup so store auth can run. |
| packages/store/src/cli/services/store/info/index.test.ts | Updates expectations to assert preview-session clearing on preview-store lookup and Admin 401. |
| packages/store/src/cli/services/store/execute/admin-transport.test.ts | Updates expectations to assert preview-session clearing on Admin 401 in execute paths. |
| packages/store/src/cli/services/store/auth/preview-claim-recovery.test.ts | Adds real LocalStorage regression coverage showing clearing unblocks the store auth flow. |
| packages/store/src/cli/services/store/admin-errors.ts | Clears stored sessions (including preview) on Admin 401/404 before throwing the reauth error. |
| .changeset/claimed-preview-store-auth-recovery.md | Patch changeset documenting the user-facing recovery fix. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
🫰✨ Thanks @dmerand! Your snapshot has been published to npm. Test the snapshot by installing your package globally: pnpm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20260819161547Caution After installing, validate the version by running |
WHY are these changes introduced?
#7986 detects a claimed preview store and tells the user to run
shopify store auth. It retains the stalekind: 'preview'session, butstore authstops inthrowIfPreviewStorebefore it can replace that session. The recovery command therefore cannot run.The old behavior retained the session so later
store infocalls repeated the claimed-preview error instead of starting normal login. After claim, normal OAuth is the required recovery. This change clears a session only after 401/404 proves that its preview credential is invalid.This is intentionally split from #8190. This PR repairs the existing
storerecovery contract. The follow-up PR will handle theme commands and its required shared transport/recovery changes.WHAT is this pull request doing?
Clear a preview session after a 401/404 proves that its token is no longer valid, then keep the existing claimed-preview reauthentication error and scope placeholder. The change covers both Preview Stores lookup and Admin API paths used by
store infoandstore execute.A real-local-storage regression test proves that the suggested
store authcommand gets past the preview-store guard after recovery.Manual testing
Use a throwaway preview store. Claiming revokes its preview credential. Use the same local CLI profile for all steps.
This snapshot tests
store infoandstore execute. Theme-command recovery is separate.(Pre-PR behavior)
Create a preview store:
Get and open its claim URL:
Open
saveUrlfrom the JSON output. Complete the browser claim as the new store owner.With the released CLI still installed, reproduce the bug:
The first command reports a likely claim. The second command fails with ``store auth
is unavailable for preview storesbecause the stale preview session blocks recovery.(Post-PR behavior)
Install the snapshot and confirm the executable version:
Expect
0.0.0-snapshot-20260819161547. If the version differs, runwhich shopifyto find the executable in use.Trigger recovery again, then authenticate:
The first command gives the same claimed-preview recovery message and clears the stale session. The second command gets past the preview guard and starts browser OAuth. Complete OAuth as the claimed store owner or another authorized user.
Verify the new stored session:
Expect the claimed store name.
To test the
store executeinvalidation path directly, repeat the flow with a new preview store. Use thestore executecommand above instead ofstore infoin steps 3 and 5. The nextstore authcommand must start OAuth rather than fail because the store is still classified as a preview store.Checklist
patchfor bug fixes ·minorfor new features ·majorfor breaking changes) and added a changeset withpnpm changeset add