24 lines
706 B
TypeScript
24 lines
706 B
TypeScript
import {
|
|
authenticateRelayNode,
|
|
authorizeDeviceForRelay,
|
|
} from "@/db/relay-control-plane";
|
|
import { apiError, readJsonMutation } from "../../../respond";
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const principal = await authenticateRelayNode(request);
|
|
const payload = await readJsonMutation<{
|
|
device_id?: string;
|
|
token_hash?: string;
|
|
}>(request);
|
|
const result = await authorizeDeviceForRelay({
|
|
principal,
|
|
deviceId: payload.device_id ?? "",
|
|
tokenHash: payload.token_hash?.trim().toLowerCase() ?? "",
|
|
});
|
|
return Response.json(result, { headers: { "cache-control": "no-store" } });
|
|
} catch (error) {
|
|
return apiError(error);
|
|
}
|
|
}
|