TheUnreal
TheUnreal

Reputation: 24472

Laravel get user info by Jwt token

I'm using laravel as my backend. Once the user has logged into my app, all I have is just a token without any information regards the username or any other user details.

Once I retrive the JWT Token and store it in my frontend (angular2), how I can get the user details?

For the record, i'm using the following laravel library: https://github.com/tymondesigns/jwt-auth

Upvotes: 2

Views: 5830

Answers (4)

Metooll
Metooll

Reputation: 1

JWTAuth::parseToken()->authenticate();

Upvotes: 0

Christopher Kikoti
Christopher Kikoti

Reputation: 2703

I have tested just

$user = JWTAuth::toUser();

Without any parameter and it works as well I am using Laravel 7.3 with tymon/jwt-auth 1.0

Upvotes: 0

Akinola Olayinka
Akinola Olayinka

Reputation: 861

To get the user information

  1. First get the token from JWTAuth like this:

    $token = JWTAuth::getToken();

  2. Then get the user from the token as follows:

    $user = JWTAuth::toUser($token);

Upvotes: 4

Hardik Savani
Hardik Savani

Reputation: 183

you can get user information like this way :

$user = JWTAuth::toUser(your_token_here);

Upvotes: 0

Related Questions