How to extend the duration of the token ? I have function with expired time but not work correctly.
protected function respondWithToken($token)
{
return response()->json([
'token' => $token,
'token_type' => 'bearer',
'expires_in' => auth()->factory()->getTTL() * 464465353454316000,
'user' => auth()->user()
]);
}
}
The token expires very quickly.
'expires_in' => auth()->factory()->getTTL() * 464465353454316000 //this line not work property. Token expired early
在终端上发布配置文件php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
打开config/jwt.php
将ttl
设置为所需的分钟数,默认为 60 分钟。
Try this, It works for me:
use JWTAuth;
...
'expires_in' => JWTAuth::factory()->getTTL() * 24,
Use setTTL to set token expires not getTTL(). getTTL function only shows how long the token expires in minutes
$token = auth()->setTTL(1440)->attempt($credentials);
//If you do this, your token will be valid for 1 day
protected function respondWithToken($token)
{
return response()->json([
'token' => $token,
'token_type' => 'bearer',
'expires_in' => auth()->factory()->getTTL(),
'user' => auth()->user()
]);
}
'expires_in' => auth()->factory()->getTTL() * 60000
如果您这样做,您的令牌将在 1 天内有效
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.