fix(theme): don't send Bearer token to cart/checkout/account proxy en…#8027
Open
gotesgan wants to merge 1 commit into
Open
fix(theme): don't send Bearer token to cart/checkout/account proxy en…#8027gotesgan wants to merge 1 commit into
gotesgan wants to merge 1 commit into
Conversation
Author
|
I have signed the CLA |
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.
Fix cart AJAX authentication in
theme devproxyWHY are these changes introduced?
Fixes #7568.
When running
shopify theme dev, Cart AJAX endpoints (such as/cart/add.js,/cart.js,/cart.json,/cart/change.js, and/cart/update.js) return401or403responses.The proxy currently attaches an
Authorization: Bearer <storefrontToken>header to every request. However, Cart AJAX endpoints authenticate using the storefront session cookie rather than a Storefront API access token. Because the Bearer token is present, SFR attempts token-based authentication instead of cookie-based authentication. The CLI's storefront token does not include the required cart scopes, causing these requests to fail.This behavior was previously fixed in commit
d0e135b8f, but was later reverted in11240b342. This PR restores the same behavior while adapting the implementation to the current codebase.WHAT is this pull request doing?
Adds a
CART_SESSION_PATTERNregex to match cart endpoints (/cart,/cart.js,/cart.json, and/cart/*).Introduces a
needsBearerToken()helper that determines whether a request should include theAuthorizationheader.Skips sending the Bearer token for:
Continues sending the Bearer token for all other requests that require Storefront API authentication.
Adds 9 new unit tests covering authentication behavior for:
How to test your changes?
Run the proxy test suite:
Expected result:
401/403while runningshopify theme dev.Post-release steps
None.
Checklist