Skip to content

Recover customer account login from OAuth state mismatches#3856

Open
fredericoo wants to merge 1 commit into
mainfrom
fb-fix-customer-account-state-recovery
Open

Recover customer account login from OAuth state mismatches#3856
fredericoo wants to merge 1 commit into
mainfrom
fb-fix-customer-account-state-recovery

Conversation

@fredericoo

Copy link
Copy Markdown
Contributor

Closes #3403

TL;DR: Customer Account login currently ends on Bad request: Unauthorized when the OAuth callback loses or replaces the storefront session state. Retry the login flow once so customers can complete authentication without re-entering their one-time code.

Before

Switching from an app WebView to the system browser, or completing an older login tab, caused customerAccount.authorize() to reject the callback and clear the customer session.

After

Hydrogen redirects through the configured login route once with a fresh OAuth transaction. If the browser still cannot retain the session, the second callback stops with a clearer error instead of looping.

What this changes

  • Recover once from missing or stale OAuth session state.
  • Preserve existing customer and buyer session data for invalid callbacks.
  • Carry the recovery marker through OAuth state so loop protection survives missing cookies.
  • Generate OAuth state with 256 bits of cryptographically secure randomness.
  • Deduplicate the recovery warning without logging state, codes, tokens, or PII.

Developer impact

Includes a patch changeset for @shopify/hydrogen. There are no new exports or public API changes.

UX impact

Customers moving from an in-app browser to Safari or Chrome, and customers using multiple login tabs, can complete login automatically instead of seeing an Unauthorized response.

Risk

  • Recovery is intentionally limited to one attempt. Persistent cookie failures still stop rather than loop.
  • Custom login routes must pass the recovery request directly to customerAccount.login(), matching the standard Hydrogen route.

How to Test

  1. Run pnpm --filter skeleton dev -- --customer-account-push with an account-enabled test shop.
  2. Open the storefront in an app WebView, start sign-in, choose Open in browser, and finish authentication.
  3. Confirm the storefront completes login instead of returning Bad request: Unauthorized.
  4. Open the sign-in link in two tabs, close the newer tab, and finish authentication in the older tab.
  5. Confirm the storefront restarts login once and completes authentication.

Customer login could fail with an Unauthorized response when the browser context changed or a concurrent login replaced session state.

Restart login once using a recovery marker carried through OAuth state, preserve existing session data, and generate state with cryptographically secure randomness.

Assisted-By: devx/39bbe0bb-8821-4cda-9954-2bbeb70c1d6a
@shopify

shopify Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Oxygen deployed a preview of your fb-fix-customer-account-state-recovery branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment July 14, 2026 3:23 PM

Learn more about Hydrogen's GitHub integration.

@fredericoo
fredericoo marked this pull request as ready for review July 14, 2026 19:08
@fredericoo
fredericoo requested a review from a team as a code owner July 14, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Customer Account login shows unfriendly error page in some cases

3 participants