llmbackend/app/Http/Middleware/AdminAuthenticate.php
Jethro Lin c44c25d86f 4. [API 详细说明](#4-api-详细说明)
- [4.1 认证 API](#41-认证-api)
     - [4.1.1 获取访问令牌](#411-获取访问令牌)
   - [4.2 客户用户 API](#42-客户用户-api)
     - [4.2.1 发送提示词请求](#421-发送提示词请求)
   - [4.3 管理员 API](#43-管理员-api)
     - [4.3.1 LLM 提供商管理](#431-llm-提供商管理)
       - [4.3.1.1 新增 LLM 提供商](#4311-新增-llm-提供商)
       - [4.3.1.2 修改 LLM 提供商](#4312-修改-llm-提供商)
       - [4.3.1.3 删除 LLM 提供商](#4313-删除-llm-提供商)
       - [4.3.1.4 获取 LLM 提供商列表](#4314-获取-llm-提供商列表)
2024-12-04 12:01:56 +08:00

30 lines
696 B
PHP

<?php
declare(strict_types=1);
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
class AdminAuthenticate
{
public function handle(Request $request, Closure $next): Response
{
if (!Auth::guard('admin')->check()) {
return response()->json([
'error' => 'unauthorized',
'message' => '未授权,请先登录。',
], 401);
}
$admin = Auth::guard('admin')->user();
// Add admin information to the request
$request->merge(['admin' => $admin]);
return $next($request);
}
}