Wp-graphql-woocommerce: GraphQL error: Expired token

Created on 22 Jun 2020  路  4Comments  路  Source: wp-graphql/wp-graphql-woocommerce

Describe the bug
I'm trying to implement the cart with GrahpQL but after i few days I get this error: Uncaught (in promise) Error: GraphQL error: Expired token. Unfortunately this error is keeping me from going into production. I can't load the cart, and I can't add to cart. The woocommerce-session is present client side and if I clear it everything works as expected. I'm fetching stock and prices with Apollo and that's working.

Here is my Apollo client.js. I'm using GatsbyJS.

Any help appreciated.

To Reproduce

  1. Add something to cart.
  2. Wait 24-48H
  3. Try to load cart

Expected behavior
Should recognise session token and load cart.

Screenshots
Screenshot 2020-06-22 at 13 50 20

Most helpful comment

@dawgor The token is a JWT token that got an expiry (~48h). Our solution was to remove the token if it has expired and set a new one in the apollo-client. Maybe not the best solution but one that is working.

Sharing the code here. The check is done in the middleware.

All 4 comments

I reckon I have to implement a token refresh mechanism in my Apollo client. But I'm unsure of what token the error is referring to? I'm not using auth for my site, does the add to cart mutation send a JWT token? As i understand the woocommerce-session token should stay the same since I want to persist the cart between sessions. Can anyone point me in the right direction? 馃檹

Hi @zamson, have you fixed it? Having the same problem, but as far as I know, as of now, only the AddToCart mutation is capable of generating a new token.

@dawgor The token is a JWT token that got an expiry (~48h). Our solution was to remove the token if it has expired and set a new one in the apollo-client. Maybe not the best solution but one that is working.

Sharing the code here. The check is done in the middleware.

@zamson Oh, i see. Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kenchoong picture kenchoong  路  5Comments

pmventura picture pmventura  路  3Comments

jake-101 picture jake-101  路  7Comments

huniqcast picture huniqcast  路  3Comments

jacobarriola picture jacobarriola  路  5Comments