Closed cc-visionary closed 1 month ago
@cc-visionary I had this error too after I upgraded from 2024.4.x to 2024.7.2.
Also make sure you add 'wss://ngrok-domain.app:*'
(replace with your ngrok domain) to your connect-src in your createContentSecurityPolicy
function call
Doing this step in the upgrade manual seemed to help the issue
// in app/lib/session.ts
export class AppSession implements HydrogenSession {
+ public isPending = false;
get unset() {
+ this.isPending = true;
return this.#session.unset;
}
get set() {
+ this.isPending = true;
return this.#session.set;
}
commit() {
+ this.isPending = false;
return this.#sessionStorage.commitSession(this.#session);
}
}
session.isPending
is true #2137// in server.ts
export default {
async fetch(request: Request): Promise<Response> {
try {
const response = await handleRequest(request);
+ if (session.isPending) {
+ response.headers.set('Set-Cookie', await session.commit());
+ }
return response;
} catch (error) {
...
}
},
};
session.commit()
in routes #2137// in route files
export async function loader({context}: LoaderFunctionArgs) {
return json({},
- {
- headers: {
- 'Set-Cookie': await context.session.commit(),
- },
},
);
}
Thank you @jnhamid
Thank you so much! It's working now!
also worked for me, thanks so much bro, didn't need step 3. I'm on 2024.7.5
What is the location of your example repository?
No response
Which package or tool is having this issue?
Hydrogen
What version of that package or tool are you using?
2024.7.2
What version of Remix are you using?
2.10.1
Steps to Reproduce
I used the shopify hydrogen skeleton template.
Then followed the documentation: https://shopify.dev/docs/storefronts/headless/building-with-the-customer-account-api/hydrogen where:
Create the Customer Account API client (didn't modify anything in the sever.js file of the template)
I also did
npx shopify hydrogen env pull
to sync the environment variables.I have also tried
npx shopify hydrogen dev --customer-account-push__unstable
which I saw in a discussion, but the result is the same.Expected Behavior
The expected behavior is that I am supposed to be logged in already.
Actual Behavior
But the website returns
Bad request: Unauthorized
and the console saysCustomer Account API Error: The session state does not match the state parameter. Make sure that the session is configured correctly and passed to 'createCustomerAccountClient'.