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

22 lines
652 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 = request.nextUrl.clone();
loginUrl.pathname = "/admin/login";
loginUrl.search = "";
loginUrl.searchParams.set("next", pathname);
return NextResponse.redirect(loginUrl);
}
return NextResponse.next();
}
export const config = {
matcher: ["/admin/:path*"],
};