Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preventing Unwanted WooCommerce Sessions from Automatic OPTIONS Requests #908

Open
pooriaset opened this issue Nov 29, 2024 · 2 comments
Open

Comments

@pooriaset
Copy link

pooriaset commented Nov 29, 2024

Describe the bug

Hello,

I encountered an issue while developing my latest project. The frontend is hosted at example.com, while the backend is at api.example.com. Due to the different domains, the browser automatically sends an OPTIONS request for CORS.

Since this is done automatically by the browser, we are unable to set the woocommerce-session header. As a result, a new session is created in the wp_woocommerce_sessions table for each OPTIONS request.

To prevent this issue, I believe it would be better to check if the request method is not OPTIONS before creating a session.

The image below illustrates the unnecessary tokens that are being created.

image

To Reproduce

Simply call services from a localhost to any backend multiple times. Even though we set the woocommerce-session header, there is nothing we can do for the OPTIONS requests.

If you agree, I can implement the necessary changes myself and submit a pull request.

Thank you!

@pooriaset pooriaset changed the title CORS Issue with WooCommerce Sessions Preventing Unwanted WooCommerce Sessions from Automatic OPTIONS Requests Nov 29, 2024
@kidunot89
Copy link
Member

kidunot89 commented Dec 9, 2024

@pooriaset What are you using to send you're GraphQL request? Apollo, React Query, fetch?

@pooriaset
Copy link
Author

I’m using Apollo, but Apollo does not have this behavior. The browser sent OPTIONS requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants