Node Auth fix and simple usage test
This commit is contained in:
+4
-1
@@ -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>)";
|
||||
|
||||
@@ -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: [],
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user