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: [],
|
||||
});
|
||||
}
|
||||
+2
-13
@@ -1,15 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
|
||||
const NotFound = () => {
|
||||
useEffect(() => {
|
||||
console.error(
|
||||
"404 Error: User attempted to access non-existent route:",
|
||||
location.pathname
|
||||
);
|
||||
}, [location.pathname]);
|
||||
|
||||
export default function NotFound() {
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-muted">
|
||||
<div className="text-center">
|
||||
@@ -23,6 +14,4 @@ const NotFound = () => {
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default NotFound;
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,13 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import { getDocker } from "@/core/docker";
|
||||
import { getDocker } from "@/core/client/docker";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div>
|
||||
<button
|
||||
onClick={() => {
|
||||
getDocker();
|
||||
onClick={async () => {
|
||||
console.log(await getDocker("localhost", "oD7tMrnkxIvuFrR+b6QZh66E4PU="));
|
||||
}}
|
||||
>
|
||||
Get docker
|
||||
|
||||
Reference in New Issue
Block a user