forked from UKSOURCE/ipv6
20 lines
535 B
TypeScript
20 lines
535 B
TypeScript
import type { NextRequest } from "next/server";
|
|
import { NextResponse } from "next/server";
|
|
|
|
export function middleware(request: NextRequest) {
|
|
const session = request.cookies.get("admin_session");
|
|
|
|
if (!session || session.value !== "true") {
|
|
// If not authenticated and trying to access admin, redirect to login
|
|
const url = request.nextUrl.clone();
|
|
url.pathname = "/login";
|
|
return NextResponse.redirect(url);
|
|
}
|
|
|
|
return NextResponse.next();
|
|
}
|
|
|
|
export const config = {
|
|
matcher: ["/admin", "/admin/:path*"],
|
|
};
|