20 lines
599 B
TypeScript
20 lines
599 B
TypeScript
import { NextResponse, type NextRequest } from "next/server";
|
|
|
|
const adminSessionCookie = "fs_admin_session";
|
|
|
|
export function proxy(request: NextRequest) {
|
|
const { pathname } = request.nextUrl;
|
|
if (!pathname.startsWith("/admin") || pathname === "/admin/login") return NextResponse.next();
|
|
|
|
if (!request.cookies.get(adminSessionCookie)?.value) {
|
|
const loginUrl = new URL("/admin/login", request.url);
|
|
loginUrl.searchParams.set("next", pathname);
|
|
return NextResponse.redirect(loginUrl);
|
|
}
|
|
|
|
return NextResponse.next();
|
|
}
|
|
|
|
export const config = {
|
|
matcher: ["/admin/:path*"],
|
|
};
|