mirror of
https://github.com/Since-3/since3-portal.git
synced 2026-10-12 19:51:17 +00:00
29 lines
No EOL
1 KiB
TypeScript
29 lines
No EOL
1 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { createClient } from "./lib/supabase/proxy";
|
|
|
|
|
|
const publicRoutes = ["/", "/impressum", "/datenschutz", "/agb"]
|
|
// Geteilte Vorlagen (/demo/<token>) öffnen Kunden ohne Login; die KI-Routen prüfen Token bzw. Admin selbst
|
|
const publicPrefixes = ["/demo/", "/api/ai/"]
|
|
|
|
export default async function proxy(request: NextRequest) {
|
|
const { supabase, response } = createClient(request)
|
|
|
|
const { data: { user } } = await supabase.auth.getUser()
|
|
|
|
const { pathname } = request.nextUrl
|
|
const isPublicRoute = publicRoutes.includes(pathname) || publicPrefixes.some((prefix) => pathname.startsWith(prefix))
|
|
|
|
if (!user && !isPublicRoute) {
|
|
const redirectResponse = NextResponse.redirect(new URL("/", request.url))
|
|
response.cookies.getAll().forEach((cookie) => redirectResponse.cookies.set(cookie))
|
|
return redirectResponse
|
|
}
|
|
|
|
return response
|
|
}
|
|
|
|
|
|
export const config = {
|
|
matcher: ["/((?!_next/static|_next/image|favicon.ico|pictures|manifest.webmanifest|apple-icon|icons/icon-).*)"],
|
|
} |