Skip to content

Commit 407b2ed

Browse files
alepefeatrincas
authored andcommitted
chore: Remove basic auth
1 parent fafcd26 commit 407b2ed

File tree

1 file changed

+1
-41
lines changed

1 file changed

+1
-41
lines changed

client/src/middleware.ts

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,10 @@
1-
import { NextRequest, NextResponse } from "next/server";
1+
import { NextResponse } from "next/server";
22

33
import { NextRequestWithAuth, withAuth } from "next-auth/middleware";
44

55
import { isPrivatePath } from "@/lib/utils";
66

77
export default function middleware(req: NextRequestWithAuth) {
8-
// HTTP Basic Auth logic
9-
function isAuthenticated(req: NextRequest) {
10-
// Skip auth if disabled via environment config
11-
const isBasicAuthEnabled =
12-
(process.env.BASIC_AUTH_ENABLED ?? "").toLowerCase() === "true";
13-
if (!isBasicAuthEnabled) return true;
14-
15-
const authHeader =
16-
req.headers.get("authorization") || req.headers.get("Authorization");
17-
if (!authHeader?.startsWith("Basic ")) return false;
18-
19-
const [user, pass] = Buffer.from(authHeader.split(" ")[1], "base64")
20-
.toString()
21-
.split(":");
22-
23-
return (
24-
user === process.env.BASIC_AUTH_USER &&
25-
pass === process.env.BASIC_AUTH_PASSWORD
26-
);
27-
}
28-
29-
const PUBLIC_FILE = /\.(.*)$/;
30-
const BASIC_AUTH_EXCLUDED_PATHS = [/^\/health\/?$/];
31-
32-
if (
33-
PUBLIC_FILE.test(req.nextUrl.pathname) ||
34-
BASIC_AUTH_EXCLUDED_PATHS.some((pattern) =>
35-
pattern.test(req.nextUrl.pathname),
36-
)
37-
) {
38-
return NextResponse.next();
39-
}
40-
41-
if (!isAuthenticated(req)) {
42-
return new NextResponse("Authentication required", {
43-
status: 401,
44-
headers: { "WWW-Authenticate": "Basic" },
45-
});
46-
}
47-
488
if (isPrivatePath(req.nextUrl.pathname)) {
499
return withAuth(req, {
5010
pages: {

0 commit comments

Comments
 (0)