Skip to content

Commit

Permalink
Use new header name for secret storefront token (#1037)
Browse files Browse the repository at this point in the history
* Update logic and name of storefront secret token

* Fix bug in Stackblitz and, really, the whole world

* Add changeset
  • Loading branch information
jplhomer authored Apr 5, 2022
1 parent 0348808 commit 13376ef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-eels-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen': patch
---

Use new header for private Storefront token
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ function getInitFromNodeRequest(request: any) {
: undefined,
};

if (!init.headers.has('x-forwarded-for')) {
init.headers.set('x-forwarded-for', request.socket.remoteAddress);
const remoteAddress = request.socket.remoteAddress;
if (!init.headers.has('x-forwarded-for') && remoteAddress) {
init.headers.set('x-forwarded-for', remoteAddress);
}

return init;
Expand Down
10 changes: 9 additions & 1 deletion packages/hydrogen/src/hooks/useShopQuery/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ function useCreateShopRequest(body: string, locale?: string) {

const extraHeaders = {} as Record<string, any>;

/**
* Only pass one type of storefront token at a time.
*/
if (secretToken) {
extraHeaders['Shopify-Storefront-Private-Token'] = secretToken;
} else {
extraHeaders['X-Shopify-Storefront-Access-Token'] = storefrontToken;
}

if (buyerIp) {
extraHeaders['Shopify-Storefront-Buyer-IP'] = buyerIp;
}
Expand All @@ -182,7 +191,6 @@ function useCreateShopRequest(body: string, locale?: string) {
body,
method: 'POST',
headers: {
'X-Shopify-Storefront-Access-Token': secretToken ?? storefrontToken,
'X-SDK-Variant': 'hydrogen',
'X-SDK-Version': storefrontApiVersion,
'content-type': 'application/json',
Expand Down

0 comments on commit 13376ef

Please sign in to comment.