我安装了JWT并登录,因此它可以工作并生成令牌,当我注销邮递员时,它返回200ok,但又一次又返回200ok,并且不生成无效令牌。
public function login(User $user)
{
$this->validate($this->request, [
'email' => 'required|email',
'password' => 'required'
]);
// Find the user by email
$user = User::where('email', $this->request->input('email'))->first();
if (!$user) {
return response()->json([
'error' => 'Email does not exist.'
], 400);
}
// Verify the password and generate the token
if (Hash::check($this->request->input('password'), $user->password)) {
return response()->json([
'token' => $this->jwt($user)
], 200);
}
// Bad Request response
return response()->json([
'error' => 'Email or password is wrong.'
], 400);
}
public function logout(Request $request)
{
JWTAuth::invalidate(JWTAuth::parseToken());
}