SPB Git
915 B · 20 lines typescript
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
Files · e271e75196f58c092c7f0be7ddb52ff27d11b54f
Menu

Theme