[英]How to expand jwt time? Jwt version : "tymon/jwt-auth": "^1.0.0-rc.2" Laravel 5.7
如何延長令牌的期限? 我的功能已過期,但無法正常工作。
protected function respondWithToken($token)
{
return response()->json([
'token' => $token,
'token_type' => 'bearer',
'expires_in' => auth()->factory()->getTTL() * 464465353454316000,
'user' => auth()->user()
]);
}
}
令牌很快過期。
'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 分鍾。
試試這個,它對我有用:
use JWTAuth;
...
'expires_in' => JWTAuth::factory()->getTTL() * 24,
使用 setTTL 設置令牌過期而不是 getTTL()。 getTTL 函數僅顯示令牌在幾分鍾內過期的時間
$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 天內有效
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.