I'm doing my authentication system with Laravel & JWT, but I have some questions.
I use the tymon jwt package
I have a token generated at login, for 24 hours, and if the remember-me box is checked, it is valid for 2 years. Except that how should I proceed to renew the token during these 2 years, I guess I don't have to keep the same one, for security reasons?
Do I have to store something in a database ? like a remember-me token for example, or a refresh-token ?
I'm a bit lost with all this, and I'd like to understand how to proceed. I've already searched quite a bit on the internet, but I can't find what I want, or it's incomplete.
public function login()
{
$credentials = request(['email', 'password']);
$ttl = env('JWT_TTL');
if (request(['remember_me']) == true) {
$ttl = env('JWT_REMEMBER_TTL');
}
if (!$token = auth()->attempt($credentials)) {
return response()->json(['error' => 'Wrong credentials'], 401);
}
return $this->respondWithToken($token, $ttl);
}
protected function respondWithToken($token, $ttl)
{
return response()->json([
'access_token' => $token,
'token_type' => 'bearer',
'expires_in' => $ttl
]);
}
JWT_TTL=1440
JWT_REMEMBER_TTL=1051200
Thanks in advance,