使用JWT认证的时候,一旦JWT_REFRESH_TTL到期,那么也是会自动退出的影响用户体验
class AuthorizationsController extends Controller
{
public function store(AuthorizationRequest $request)
{
$credentials = [
'phone' => $request->phone,
'password' => $request->password
];
if (!$token = \Auth::guard('api')->attempt($credentials)) {
throw new AuthenticationException('用户名或密码错误');
}
return $this->respondWithToken($token)->setStatusCode(201);
}
protected function respondWithToken($token)
{
return response()->json([
'access_token' => $token,
'token_type' => 'Bearer',
'expires_in' => auth('api')->factory()->getTTL() * 60
]);
}
public function update()
{
$token = auth('api')->refresh();
return $this->respondWithToken($token);
}
public function destroy()
{
auth('api')->logout();
return response(null, 204);
}
}
使用的软件包是tymon/jwt-auth
不过就算把JWT_REFRESH_TTL设置的比较久,仍然会存在用户在某一天操作的时候突然被T出来,这个你们是怎么解决的
假如说JWT_REFRESH_TTL设置为1天,然后你现在下午1点钟登录,明天12点半操作,半个小时后还是仍然会突然退出,时间设置久了也是一样会存在这样的问题,只是频率小而已
推荐文章: