• I integrated it with my Flutter app, and it works flawlessly.

    Here is a little piece of code that I implemented to get User ID and Role:

    add_filter('jwt_auth_token_before_dispatch', 'add_user_id_and_role_to_jwt_response', 10, 2);
    
    function add_user_id_and_role_to_jwt_response($data, $user) {
        // Aggiungi il campo 'user_id' al JSON della risposta
        $data['user_id'] = $user->data->ID;
    
        // Ottieni il ruolo dell'utente
        $user_roles = $user->roles;
        $user_role = !empty($user_roles) ? $user_roles[0] : '';
    
        // Aggiungi il campo 'user_role' al JSON della risposta
        $data['user_role'] = $user_role;
    
        // Restituisci il nuovo array dati modificato
        return $data;
    }
    • This topic was modified 8 months, 3 weeks ago by graficowalab.
  • The topic ‘Simply perfect!’ is closed to new replies.