1
0
Fork 0
polaris-task-force/src/lib/arma-bridge/auth.ts
Z8MB1E fc3b961a43 feat(arma-bridge): add authenticated v1 bridge API routes
Add key-and-server-id authenticated endpoints for server heartbeat, event ingestion, and command pull/ack.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-08-23 18:51:33 -04:00

10 lines
632 B
TypeScript

import { NextRequest, NextResponse } from "next/server";
export function authenticateArmaBridge(req: NextRequest): string | NextResponse {
const secret = process.env.ARMA_BRIDGE_API_KEY;
if (!secret) return NextResponse.json({ error: "Arma bridge is not configured." }, { status: 503 });
if (req.headers.get("x-arma-bridge-key") !== secret) return NextResponse.json({ error: "Unauthorized." }, { status: 401 });
const serverId = req.headers.get("x-arma-server-id");
if (!serverId || !/^[a-zA-Z0-9_-]{3,64}$/.test(serverId)) return NextResponse.json({ error: "Invalid server id." }, { status: 400 });
return serverId;
}