fix: use createBrowserClient for proper cookie-based auth
- Switch from @supabase/supabase-js to @supabase/ssr createBrowserClient - This stores session in cookies instead of localStorage - Allows middleware to access session server-side - Fixes the missing cookies issue,description:Commit cookie auth fix
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { createClient } from '@supabase/supabase-js'
|
||||
import { createBrowserClient } from '@supabase/ssr'
|
||||
|
||||
// Support both EXPO_PUBLIC_ (mobile) and NEXT_PUBLIC_ (web) prefixes
|
||||
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
|
||||
@@ -14,12 +14,12 @@ if (typeof window !== 'undefined') {
|
||||
console.log('Using NEXT_PUBLIC:', !!process.env.NEXT_PUBLIC_SUPABASE_URL)
|
||||
}
|
||||
|
||||
export const supabase = createClient(supabaseUrl, supabaseKey, {
|
||||
auth: {
|
||||
autoRefreshToken: true,
|
||||
persistSession: true,
|
||||
},
|
||||
})
|
||||
// Use createBrowserClient for proper cookie handling in Next.js
|
||||
// This stores the session in cookies so middleware can access it
|
||||
export const supabase = createBrowserClient<Database>(
|
||||
supabaseUrl,
|
||||
supabaseKey
|
||||
)
|
||||
|
||||
export const isSupabaseConfigured = () => {
|
||||
const url = process.env.NEXT_PUBLIC_SUPABASE_URL
|
||||
@@ -139,4 +139,4 @@ export interface Database {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user