feat: 添加退出接口

This commit is contained in:
2025-03-14 14:40:56 +08:00
parent 289d9afcc5
commit a922915eb8
2 changed files with 22 additions and 5 deletions

View File

@@ -11,14 +11,14 @@ use thans\jwt\facade\JWTAuth;
use think\facade\Cache; use think\facade\Cache;
/** /**
* 登录控制器 * 用户中心控制器
*/ */
class Login class UserCenter
{ {
/** /**
* 登录验证接口 * 登录验证接口
*/ */
public function index() public function login()
{ {
// 获取参数 // 获取参数
$post = request()->post([ $post = request()->post([
@@ -89,4 +89,18 @@ class Login
'token' => $token, 'token' => $token,
]); ]);
} }
// 退出登录
public function logout()
{
$token = request()->header('Authorization');
if (\think\helper\Str::startsWith($token, 'Bearer ')) {
$token = substr($token, 7);
}
// token 加入黑名单
JWTAuth::invalidate($token);
return success('操作成功');
}
} }

View File

@@ -23,7 +23,10 @@ Route::group('v1', function () {
]); ]);
// 登录接口 // 登录接口
Route::post('login', 'Login/index'); Route::post('login', 'UserCenter/login');
// 登出接口
Route::get('logout', 'UserCenter/logout');
// 获取用户菜单权限 // 获取用户菜单权限
Route::get('{id}/menu', 'User/menu'); Route::get('{id}/menu', 'User/menu');