Xboard/app/Http/Middleware/Admin.php

32 lines
676 B
PHP
Raw Normal View History

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