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.