Getting an Issue while generating a token at login time
-
Hi, actually I am trying to generate token at my login time using an wp_login hook but i am unable to do so, can you provide me any way to do it.
Tell me whether there is any buildin function is there that I can use.
add_action(‘wp_login’, function ($user_login, $user) {
if (!user_can($user, ‘dokandar’)) {
return;
}$response = wp_remote_post(site_url('/wp-json/jwt-auth/v1/token'), [ 'body' => [ 'username' => $user_login, 'password' => 'YOUR_DEFAULT_PASSWORD_IF_AVAILABLE', // Not ideal, see note below ], ]); if (is_wp_error($response)) { error_log('Token request failed: ' . $response->get_error_message()); return; } $body = json_decode(wp_remote_retrieve_body($response), true); if (!empty($body['token'])) { update_user_meta($user->ID, 'vendor_jwt_token_key', $body['token']); } else { error_log('JWT token missing: ' . json_encode($body)); }}, 10, 2); I am using this thing but thing is password can’t be accessed directly in wordpress.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Getting an Issue while generating a token at login time’ is closed to new replies.