You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to figure out how to obtain a WooCommerce session token for the user if they don't sign in. I am using GatsbyJS for my front-end. I want customers to be able to checkout without signing in. I did some poking around in the GatsbyJS demo theme, and if I don't sign in, I can see the woocommerce-session header being sent on every GraphQL API request, but I can't figure out how that token is being obtained.
So how do I get one of these tokens without signing in so I can track cart items and checkout inside a WC anonymous customer session without signing in? The demo theme is clearly sending a JWT to the GraphQL API when I add items to my cart. So it's clearly getting a session from somewhere. However when I look at the source code, I only see the cart items being stored in local storage. I can't find any reference to the GraphQL API being used for the cart in the source code, but the demo itself is clearly making a request with a token to add items to my cart in a WooCommerce customer session, and I am not signed in. I deleted my cookies to be sure.
The text was updated successfully, but these errors were encountered:
The WooCommerce session comes back in the headers of the response from the addToCart mutation. You can catch the incoming session token and store it in whatever way fits best for your app (localstorage, context, etc).
Apollo has some handy middleware that allows you to automatically listen for those headers (which come in as woocommerce-session).
It also has a handy middleware to send the session header on each request (ie adding an additional item to a cart, or getting cart items). That way you don't have to worry about authentication. As long as the session is in the header, WooCommerce will know what to do. 🙌🏽
@kidunot89 has a good example written here that I'm using in my app: #88
@jacobarriola@kidunot89 Thanks! I'm not too familiar with Apollo so that explains why I couldn't find the code actually interacting with the session header.
I am trying to figure out how to obtain a WooCommerce session token for the user if they don't sign in. I am using GatsbyJS for my front-end. I want customers to be able to checkout without signing in. I did some poking around in the GatsbyJS demo theme, and if I don't sign in, I can see the
woocommerce-session
header being sent on every GraphQL API request, but I can't figure out how that token is being obtained.So how do I get one of these tokens without signing in so I can track cart items and checkout inside a WC anonymous customer session without signing in? The demo theme is clearly sending a JWT to the GraphQL API when I add items to my cart. So it's clearly getting a session from somewhere. However when I look at the source code, I only see the cart items being stored in local storage. I can't find any reference to the GraphQL API being used for the cart in the source code, but the demo itself is clearly making a request with a token to add items to my cart in a WooCommerce customer session, and I am not signed in. I deleted my cookies to be sure.
The text was updated successfully, but these errors were encountered: