wp-graphql-woocommerce icon indicating copy to clipboard operation
wp-graphql-woocommerce copied to clipboard

Send (and check for) woocommerce-session as a cookie instead of header.

Open revnelson opened this issue 2 years ago • 3 comments

Is your feature request related to a problem? Please describe. Many frontend graphql clients require modifying the fetch function to get access to response headers and then we have to write functions to store and retrieve the cart session from something like localStorage. In SvelteKit, I'm currently having to make an API endpoint solely for checking for the woocommerce-session header, set is as a set-cookie for the response to the client, and then look for the cookie on requests from the client and set it back as a regular header. If it's sent from the headless wordpress as an httpOnly cookie, many client configurations would be much simpler.

Describe the solution you'd like I'd like the cart session token to be sent as an httplOnly cookie. The plugin would then need to check for the presence of the cookie on incoming requests.

Describe alternatives you've considered Either storing the woocommerce-session header value in localStorage and setting it on each outgoing request, or making an API endpoint to implement the cookie functionality to reduce client-side code.

revnelson avatar Jun 09 '22 02:06 revnelson

@revnelson Why not just use the set define( 'NO_QL_SESSION_HANDLER', true);. This would make WooGraphQL default to traditional WooCommerce session handler which uses a HTTP cookie.

kidunot89 avatar Jun 15 '22 21:06 kidunot89

@revnelson Why not just use the set define( 'NO_QL_SESSION_HEADER', true);. This would make WooGraphQL default to traditional WooCommerce session handler which uses a HTTP cookie.

Just a small fix:

Correct: NO_QL_SESSION_HANDLER Not: NO_QL_SESSION_HEADER

victormattosvm avatar Jul 23 '22 20:07 victormattosvm

☝🏿 Yea, what he said. Good catch on that @victormattosvm

kidunot89 avatar Aug 26 '22 19:08 kidunot89