funktechnik-schubert-website/proxy.ts
2026-07-03 22:25:04 +02:00

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*"],
};