public function logout() { //获取当前用户token $token = \JWTAuth::getToken(); //让token失效 try { \JWTAuth::invalidate($token); return return_rest('1', '', '已退出登录'); } catch (\Exception $e) { return return_rest('0', '', $e->getMessage()); } }
public static function invalidateTokenByUserId($userId) { $maps = \DB::table('token_map')->where('user_id', $userId)->get(); if (!empty($maps) && is_array($maps)) { foreach ($maps as $map) { try { \JWTAuth::invalidate($map->token); } catch (TokenExpiredException $e) { //If the token is expired already then do nothing here. } } } return \DB::table('token_map')->where('user_id', $userId)->delete(); }
/** * Log the user out of the application. * * @return Illuminate\Http\Response */ public function getLogout() { JWTAuth::invalidate(JWTAuth::getToken()); return $this->response->array(array('message' => 'Successfully logged out')); }