Spaces:
Sleeping
Sleeping
| import { createServerClient } from "@supabase/ssr"; | |
| import { NextResponse, type NextRequest } from "next/server"; | |
| export function proxy(request: NextRequest) { | |
| let supabaseResponse = NextResponse.next({ request }); | |
| // Skip Supabase auth if env vars not set (local dev without Supabase) | |
| if (!process.env.NEXT_PUBLIC_SUPABASE_URL || !process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY) { | |
| return supabaseResponse; | |
| } | |
| const supabase = createServerClient( | |
| process.env.NEXT_PUBLIC_SUPABASE_URL, | |
| process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY, | |
| { | |
| cookies: { | |
| getAll() { | |
| return request.cookies.getAll(); | |
| }, | |
| setAll(cookiesToSet) { | |
| cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value)); | |
| supabaseResponse = NextResponse.next({ request }); | |
| cookiesToSet.forEach(({ name, value, options }) => | |
| supabaseResponse.cookies.set(name, value, options) | |
| ); | |
| }, | |
| }, | |
| } | |
| ); | |
| // Refresh session tokens | |
| supabase.auth.getUser(); | |
| return supabaseResponse; | |
| } | |
| export const config = { | |
| matcher: ["/dashboard-pages/:path*", "/auth/:path*"], | |
| }; | |