I have installed jwt-auth in my Laravel 5.1. Couple of questions if someone can help please:
1) What is the default expiry time for a new token that is generated after login? Is it 1 hours, 1/2 hour or 15 mins?
2) How do I change the expiry time for the token when they are generated? Say, if I want to increase the token validity to 24 hours from the time they login?
At the moment, the tokens are created like this:
public function login(Request $request)
{
$credentials = $request->only('username', 'password');
try {
// verify the credentials and create a token for the user
if (! $token = JWTAuth::attempt($credentials)) {
return response()->json(['error' => 'Invalid Login Credentials'], 401);
}
} catch (JWTException $e) {
// something went wrong
return response()->json(['error' => 'Could Not Create Token'], 500);
}
// if no errors are encountered we can return a JWT
return response()->json(compact('token'));
}
The default is 60 minutes and it should be in your config/jwt.php file under the ttl option. 1440 minutes is one day so if you change it to that, users will have a valid token for up to a day.
Fantastic. Thank you so much Jeremy for pointing that out. It helps heaps! Cheers!
You're welcome :>
Very thanks @w0rd-driven for this, really i spent 2-3 hours to set token expiry. its was only set in jwt.php file.
Thanks
Rohit
Most helpful comment
The default is 60 minutes and it should be in your
config/jwt.phpfile under thettloption. 1440 minutes is one day so if you change it to that, users will have a valid token for up to a day.