This commit is contained in:
2026-08-05 14:05:08 +08:00
parent 9ffc9687d0
commit e831ce810b
8 changed files with 39 additions and 37 deletions

View File

@@ -2,10 +2,13 @@
namespace app\admin\middleware;
use app\common\Trait\ApiResponse;
use think\facade\Session;
class Auth
{
use ApiResponse;
/**
* 无需 admin 角色即可访问的路由名称(方法名小写)
*/
@@ -31,7 +34,7 @@ class Auth
public function handle($request, \Closure $next)
{
if (!Session::has('user_info')) {
return json(['code' => 401, 'msg' => '未登录,请先登录']);
return $this->error('未登录,请先登录', [], 401);
}
$user = Session::get('user_info');
@@ -45,7 +48,7 @@ class Auth
// admin 专用接口
if (in_array($action, $this->adminActions) && $role !== 'admin') {
return json(['code' => 403, 'msg' => '权限不足,仅管理员可执行此操作']);
return $this->error('权限不足,仅管理员可执行此操作', [], 403);
}
return $next($request);