Fix: Add cookiePath config option for multi-shop non-embedded apps#3106
Open
byrichardpowell wants to merge 1 commit intomainfrom
Open
Fix: Add cookiePath config option for multi-shop non-embedded apps#3106byrichardpowell wants to merge 1 commit intomainfrom
byrichardpowell wants to merge 1 commit intomainfrom
Conversation
Non-embedded apps sharing a single `shopify_app_session` cookie at path=/ experience silent session collisions when multiple shops are authenticated in separate browser tabs — each OAuth callback overwrites the previous shop's cookie. The new optional `cookiePath: string | ((session) => string)` config option lets apps scope the session cookie to a shop-specific URL prefix so each shop's cookie coexists independently in the browser. Fixes #451 Related: Shopify/shopify-app-template-react-router#156 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WHY are these changes introduced?
Fixes #451
Related: Shopify/shopify-app-template-react-router#156
Non-embedded apps that support multiple shops simultaneously in separate browser tabs hit a cookie collision: all shops share a single
shopify_app_sessioncookie scoped topath=/, so each OAuth callback silently overwrites the previous shop's session. The user in Tab A then unknowingly operates on Tab B's shop after Tab B completes auth.This is a known limitation acknowledged by
paulomargin issue #451 (Sept 2023) and has since resurfaced in the React Router template repo.WHAT is this pull request doing?
Adds an optional
cookiePathconfig option toConfigParams(in@shopify/shopify-api) that controls thepathattribute written on theshopify_app_sessioncookie during OAuth callback.Before: hardcoded
path: '/'— domain-wide, one cookie shared across all shops.After: configurable via a static string or a per-session factory function:
When each shop is served under a distinct URL prefix, the browser maintains one cookie per shop and delivers only the matching cookie per request — no collision.
Changes:
lib/base-types.ts— addscookiePath?: string | ((session: Session) => string)toConfigParamswith full JSDoclib/auth/oauth/oauth.ts— resolves the configured path at callback time and passes it tosetAndSign/, static string path, factory function pathminorbump for@shopify/shopify-apiNote: this fix requires apps to structure their routing with shop-scoped URL prefixes. The library cannot derive the path automatically (see investigation notes on the chicken-and-egg read-time problem). The JSDoc explains this requirement.
Type of change
Checklist
pnpm changesetto create a draft changelog entry (do NOT update theCHANGELOG.mdfiles manually)