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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s