Shared Authentication Mechanism for Next JS and WordPress WooCommerce [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 16 hours ago. Improve this question I’m working on an e-commerce website for a jewelry shop using WordPress and WooCommerce. The website includes a product customization feature for necklaces and bracelets, which redirects users to a Next.js app where they can customize the product in a 3D view using React Three Fiber. Here's how my setup works: Users browse products on the WordPress WooCommerce site. When they click "Customize," they are redirected to a Next.js link for customization. I'm using the JWT Authentication Token Plugin in WordPress to manage user authentication. The REST API in WordPress and Next.js handles interactions between the sites. Setup Details: WordPress WooCommerce for e-commerce functionality. JWT Authentication Token Plugin for user login. Next.js for product customization with React Three Fiber. REST API for communication between WordPress and Next.js. The challenge I'm facing: I need to check if the user is already logged into the WordPress site before allowing them to proceed with customization. I don’t want to pass the JWT token via the URL for security reasons. Instead, I would like to store the token in a cookie in WordPress and access that cookie from my Next.js site to validate the user session. My questions: How can I securely store the JWT token in a WordPress cookie and ensure it is accessible in my Next.js app (without passing the token via the URL)? Once the token is stored in the cookie, how can I access it server-side in my Next.js app to validate the token using the WordPress REST API? What would be the best practices for securely handling this cross-domain token sharing (since both WordPress and Next.js are under the same root domain)? Are there any other recommended approaches or plugins to handle this kind of JWT authentication between WordPress and Next.js? I’ve already looked through some documentation and videos but haven’t found a reliable solution for this particular case. Any help or advice would be greatly appreciated! Thank you!

Comment (0)

You’ll be in good company