SupabaseS
Supabase•8mo ago
puffybatman

Sub domain cookies issue in sveltekit

i have two subdomains, u login in on app1.domain.com. but want to reuse the cookies on app2.domain...

my understanding was to set the domain in the hook.server see below:


const supabase = createServerClient(
        'https://your-project-id.supabase.co',
        'public-anon-key', 
        {
            cookieOptions: {
                domain: isProd ? ".domain" : ".localhost", 
                path: '/',
                sameSite: 'lax',
                secure: isProd,
                httpOnly: true,
                maxAge: 60 * 60 * 24 * 30 // 30 days
            },
            cookies: {
                getAll: () => event.cookies.getAll(),
                setAll: (cookiesToSet) => {
                    cookiesToSet.forEach(({ name, value, options }) => {
                        event.cookies.set(name, value, {
                            ...options,
                            path: options?.path ?? '/',
                            domain: isProd ? ".domain" : ".localhost"
                        });
                    });
                }
            }
        }


obvs above dont work 🤔
Was this page helpful?