Files
vulhub/base/next.js/15.2.2/middleware.js
Aaron 63285f61aa
Some checks failed
Vulhub Format Check and Lint / format-check (push) Has been cancelled
Vulhub Format Check and Lint / markdown-check (push) Has been cancelled
Vulhub Docker Image CI / longtime-images-test (push) Has been cancelled
Vulhub Docker Image CI / images-test (push) Has been cancelled
first commit
2025-09-06 16:08:15 +08:00

33 lines
1.1 KiB
JavaScript

import { NextResponse } from "next/server";
export function middleware(request) {
// // Get the pathname of the request
// const { pathname } = request.nextUrl;
// // Skip middleware for login page and static assets
// if (pathname.startsWith("/login")) {
// return NextResponse.next();
// }
// Check if user is authenticated by looking for the auth cookie
const username = request.cookies.get("next_username")?.value;
const password = request.cookies.get("next_password")?.value;
console.log("user authenticated", username, password);
// User is authenticated, allow access to the requested page
if (username === "admin" && password === "password") {
return NextResponse.next();
} else {
request.cookies.delete("next_username");
request.cookies.delete("next_password");
}
// If user is not authenticated, redirect to login page
const loginUrl = new URL("/login", request.url);
return NextResponse.redirect(loginUrl);
}
export const config = {
matcher: ["/((?!api|static|.*\\..*|_next|favicon.ico|robots.txt|login).*)"],
};