From d76229478d8832f46a94002a2c92f5b5fc4ec1e2 Mon Sep 17 00:00:00 2001 From: dzinesco Date: Sat, 12 Jul 2025 21:01:43 -0600 Subject: [PATCH] fix: Resolve Supabase SSR cookie handling and auth test page issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add null checks for cookies object in Supabase SSR client - Fix auth test page to use Astro.cookies instead of Astro.request - Prevent "Cannot read properties of undefined" errors in cookie handling - Ensure proper unified auth usage pattern in test pages 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/lib/supabase-ssr.ts | 3 +++ src/pages/auth-test-unified.astro | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/supabase-ssr.ts b/src/lib/supabase-ssr.ts index 9f00e38..90d2710 100644 --- a/src/lib/supabase-ssr.ts +++ b/src/lib/supabase-ssr.ts @@ -12,12 +12,15 @@ export function createSupabaseServerClient( { cookies: { get(name: string) { + if (!cookies) return undefined; return cookies.get(name)?.value }, set(name: string, value: string, options: CookieOptions) { + if (!cookies) return; cookies.set(name, value, options) }, remove(name: string, options: CookieOptions) { + if (!cookies) return; cookies.delete(name, options) }, }, diff --git a/src/pages/auth-test-unified.astro b/src/pages/auth-test-unified.astro index 93ed8d2..7b4f7f4 100644 --- a/src/pages/auth-test-unified.astro +++ b/src/pages/auth-test-unified.astro @@ -11,8 +11,8 @@ let cookies = null; let headers = null; try { - // Test unified auth - auth = await verifyAuth(Astro.request); + // Test unified auth - use Astro.cookies for pages + auth = await verifyAuth(Astro.cookies); // Capture debug info cookies = Astro.request.headers.get('Cookie') || 'No cookies';