Xboard/app/Http/Middleware/Admin.php
xboard 0f43fff242
Some checks are pending
Docker Build and Publish / build (push) Waiting to run
feat: new xboard
2025-01-21 14:57:54 +08:00

32 lines
676 B
PHP
Executable File

<?php
namespace App\Http\Middleware;
use App\Exceptions\ApiException;
use Illuminate\Support\Facades\Auth;
use Closure;
class Admin
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!Auth::guard('sanctum')->check()) {
throw new ApiException('未登录或登陆已过期', 403);
}
$user = Auth::guard('sanctum')->user();
if (!$user->is_admin) {
throw new ApiException('无管理员权限', 403);
}
return $next($request);
}
}