spb/chat-spboucher-ai
Public
1import { NextResponse, type NextRequest } from "next/server";23const PUBLIC = new Set(["/login", "/manifest.webmanifest", "/sw.js", "/api/auth/login", "/api/health", "/offline"]);45export function proxy(req: NextRequest) {6 const { pathname } = req.nextUrl;7 if (PUBLIC.has(pathname) || pathname.startsWith("/_next") || pathname.startsWith("/icons") || pathname === "/favicon.ico") return NextResponse.next();8 const has = req.cookies.get("csa_session")?.value;9 if (!has) {10 if (pathname.startsWith("/api/")) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });11 const url = req.nextUrl.clone(); url.pathname = "/login"; url.searchParams.set("next", pathname);12 return NextResponse.redirect(url);13 }14 const res = NextResponse.next();15 res.headers.set("Cache-Control", "private, no-store");16 return res;17}1819export const config = { matcher: ["/((?!_next/static|_next/image).*)"] };20