• Resolved Youssuf Abramo

    (@youssufabramo)


    Hello, when I make a request the response carries this information:

    { "token": "example_token", "user_email": "example@example.example", "user_nicename": "example-pw", "user_display_name": "example-user", }

    I need to add user_id as a variable included in the response, I have edited in this file public/class-jwt-auth-public.php and in the line num #196 I have edited this code:

    /** The token is signed, now create the object with no sensible user data to the client*/	$data = [	'token' => $token,	'user_email' => $user->data->user_email,	'user_nicename' => $user->data->user_nicename,	'user_display_name' => $user->data->display_name,	];

    to this code:

    /** The token is signed, now create the object with no sensible user data to the client*/	$data = [	'token' => $token,	'user_email' => $user->data->user_email,	'user_nicename' => $user->data->user_nicename,	'user_display_name' => $user->data->display_name,	'user_id' => $user->data->user_id,	'userId' => $user->data->id,	];

    I have tried $user->data->user_id and $user->data->id but the code didn’t work the response back NULL in the user_id and userId

    this is the response:

    { "token": "example_token", "user_email": "example@example.example", "user_nicename": "example-pw", "user_display_name": "example-user", "user_id": null, "userId": null, }

    Any help please?

Viewing 1 replies (of 1 total)
  • Thread Starter Youssuf Abramo

    (@youssufabramo)

    I’ve resolved the issue… the problem was 'userId' => $user->data->id it should be ID instead of id , so the correct code is

    $data = [	'token' => $token,	'user_email' => $user->data->user_email,	'user_nicename' => $user->data->user_nicename,	'user_display_name' => $user->data->display_name,	'user_id' => $user->data->ID,	];
Viewing 1 replies (of 1 total)

The topic ‘How to add other variables in the API response?’ is closed to new replies.