first commit
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
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
This commit is contained in:
32
base/next.js/15.2.2/middleware.js
Normal file
32
base/next.js/15.2.2/middleware.js
Normal file
@@ -0,0 +1,32 @@
|
||||
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).*)"],
|
||||
};
|
Reference in New Issue
Block a user