23 lines
500 B
PHP
23 lines
500 B
PHP
<?php
|
|
|
|
namespace app\middleware;
|
|
|
|
use think\exception\HttpResponseException;
|
|
|
|
class AdminAuth
|
|
{
|
|
public function handle($request, \Closure $next)
|
|
{
|
|
$user = $request->authUser ?? null;
|
|
if (!$user || ($user['role'] ?? '') !== 'admin') {
|
|
throw new HttpResponseException(json([
|
|
'code' => 1,
|
|
'message' => '无管理员权限',
|
|
'data' => null,
|
|
], 403));
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|