Gujarat Santana Gujarat Santana - 1 year ago 56
PHP Question

How to get email from generated token

Hi I'm trying to get the email user from the given token. I've tried this to parse the token but I always got empty or

value according to this example :

public function getAuthenticatedUser()
try {
if (! $user = JWTAuth::parseToken()->authenticate()) {
return response()->json(['user_not_found'], 404);

} catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $e) {

return response()->json(['token_expired'], $e->getStatusCode());

} catch (Tymon\JWTAuth\Exceptions\TokenInvalidException $e) {

return response()->json(['token_invalid'], $e->getStatusCode());

} catch (Tymon\JWTAuth\Exceptions\JWTException $e) {

return response()->json(['token_absent'], $e->getStatusCode());


// the token is valid and we have found the user via the sub claim
return $user;

I put the token on the url like this localhost:8000/admin/user/get_all?token={{token}}, I also add the token in the header as
NOTE : I'm using postman to make the request. But when I try to pass the parse value to the response I always got
value :

$result = $this->getAuthenticatedUser();
return response()
'data'=> $users,

Correct me if I'm wrong here : parse meaning to get the info of the authenticate user such as email?

Note : I'm using laravel 5.2, and on the route I've builtin middleware jwt-auth and I'm using this library for generate the token.

Answer Source

It looks like the response is correct but I don't know why is only got {} but actually is not empty, when I tried to get the column table name like email :


I got the actual email that logged using that token, so now I got it now, thanks everyone.