skip to Main Content

Laravel Generate JWT Auth Token Using User Object.

Laravel generate JWT auth token using user object.


Today, we learn how to generate JWT auth token using user object. As per now, we generate the JWT auth token using username and password. But Also, we generate JWT auth token using user object. So let’s see how we can generate JWT auth token with the user object.

First of all, I hope you installed JWT auth package on Laravel, If not please follow this tutorial about JWT auth.

First of all, we can create the user object by user Id.

$user = User::find( $user_id );
$token = JWTAuth::fromUser($user);

You can use above token for authenticating user request.

So, we generate the JWT auth token based on the user object.

If you have any queries or face any issue write the comment below.

Saroj

I am a web designer and developer part-time blogger. Write something on some free time. Find my every day thought here :)

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top