0

I'm currently working on a shop like project that uses React as frontend and Wordpress with Woocommerce as a backend.

To authenticate with the API I use the JWT Authentication for WP REST API, which works great.

The problem I'm facing is that I want to redirect to a checkout page that is not part of the PWA but a traditional Wordpress page. Is there any way that I can create a WP session using the JWT token I created for the API?

The alternative would be to store the login data and pass it on to the checkout page. But I'd rather avoid this because of security concerns.

  • You could either post it a 'log me in' endpoint, and even use the existing login mechanism if you create an 'authenticate' filter that unpacks the token and returns the user if appropriate - see e.g. wp_authenticate_username_password as an example you can build on. Or you could save the token in a cookie and override the determine_current_user filter to use this as the session cookie, in the same way that wp_validate_logged_in_cookie does. Apologies I don't know the specifics: hopefully someone can write one or both of these up properly as an answer. – Rup Sep 18 at 23:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.