Node Auth fix and simple usage test

This commit is contained in:
2025-12-27 02:48:32 +01:00
parent 38c2c9fb6d
commit d92b92450f
7 changed files with 323 additions and 17 deletions
+4 -1
View File
@@ -5,7 +5,10 @@ import { NextRequest } from "next/server";
export default async function testAuth(
req: NextRequest
): Promise<null | string> {
const auth = req.headers.get("Authorization")?.replaceAll("ApiKey", "");
const auth = req.headers
.get("Authorization")
?.replaceAll("ApiKey", "")
.trim();
if (!auth)
return "Missing Authorization header (Authorization: ApiKey <key>)";
+19
View File
@@ -0,0 +1,19 @@
import { NextRequest, NextResponse } from "next/server";
import testAuth from "../auth";
import { StatusCodes } from "http-status-codes";
export async function GET(req: NextRequest): Promise<NextResponse> {
const auth = await testAuth(req);
if (auth) {
return NextResponse.json(
{ message: auth },
{ status: StatusCodes.UNAUTHORIZED }
);
}
return NextResponse.json({
message: "ok",
containers: [],
});
}