Getting JWT token for logged user
-
In my WordPress website I am hosting a web app made in React and I would like WordPress users to be synced with the app, using WordPress standard authentication (so I don’t actually know my users’ passwords).
If the user is logged in in WordPress, I would like to automatically log in the React app with that specific user.
React is trying to get the JWT token with a POST request to https://mysite.com/wp-json/jwt-auth/v1/token and in the form data is setting custom_auth=1.
I tried this:
function mysite_autologin($custom_auth_error, $username, $password, $custom_auth) { $result = $custom_auth_error; if (is_user_logged_in()) { $result = wp_get_current_user(); } return $result; } add_filter( 'jwt_auth_do_custom_auth', 'mysite_autologin', 10, 4);
Unfortunately React always gets a 403 error:
{"success":false,"statusCode":403,"code":"jwt_auth_custom_auth_failed","message":"Custom authentication failed.","data":[]}
Is there any way to expose JWT token if the user has already logged in via WordPress authentication?
Many thanks in advance, all the best.
Marco
- The topic ‘Getting JWT token for logged user’ is closed to new replies.