SPB Git

Repository Public

proxy.ts 838 B 16 lines typescript

1import { NextResponse, type NextRequest } from "next/server";23// First gate: without a session cookie, pages go to /connexion. The cookie's validity is checked against the database4// by the app layout and by every API route (this file must stay free of database access).5const COOKIE = process.env.NODE_ENV === "production" ? "__Host-sptv" : "sptv";67export function proxy(req: NextRequest) {8  if (req.cookies.get(COOKIE)?.value) return NextResponse.next();9  const url = req.nextUrl.clone();10  const next = req.nextUrl.pathname + req.nextUrl.search;11  url.pathname = "/connexion"; url.search = next && next !== "/" ? `?next=${encodeURIComponent(next)}` : "";12  return NextResponse.redirect(url);13}1415export const config = { matcher: ["/((?!api|m3u|relay|connexion|_next|icons|manifest.webmanifest|sw.js|favicon.ico|robots.txt).*)"] };16
Files main
Menu

Theme