Fix inconsistent line endings across all project files for cross-environment consistency. Add complete unit test suite covering core utilities, API routes, and server services. Add Playwright E2E test setup with smoke, auth, and agent API tests. Update all project configuration files to match standardized formatting. Fix MCP API error handling to properly propagate HTTP status codes and use correct JSON-RPC error codes. Add VSCode workspace configuration, extensions, and example MCP config files. Update .gitignore to exclude new test and build artifacts.
17 lines
516 B
TypeScript
17 lines
516 B
TypeScript
import { NextRequest } from "next/server";
|
|
|
|
export function assertAgentAuth(req: NextRequest) {
|
|
const expected = process.env.AGENT_API_KEY;
|
|
if (!expected) {
|
|
throw new Error("AGENT_API_KEY is not configured.");
|
|
}
|
|
|
|
const authHeader = req.headers.get("authorization") || "";
|
|
const token = authHeader.startsWith("Bearer ") ? authHeader.slice(7) : "";
|
|
|
|
if (token !== expected) {
|
|
const error = new Error("Unauthorized");
|
|
(error as Error & { status?: number }).status = 401;
|
|
throw error;
|
|
}
|
|
}
|