d2a / auth.ts
fxlinux's picture
Upload 12 files
bc0be9c verified
raw
history blame contribute delete
431 Bytes
// auth.ts
import { getToken } from "./utils.ts";
import { unauthorizedResponse } from "./response.ts";
export function validateAuth(req: Request): Response | null {
const token = getToken();
if (!token) return null; // 无需认证
const auth = req.headers.get("authorization") ?? "";
if (auth !== token) {
return unauthorizedResponse("无效的客户端 API 密钥", 403);
}
return null; // 认证通过
}