🚨 Cross-subdomain authentication issue: Supabase session cookie Domain attribute
Hello Supabase team and community,
I am encountering an issue with cross-subdomain authentication for my application, which uses Supabase for user management. My goal is to achieve a single login session that persists across my main domain (
Problem Description: When a user signs in on
Steps to Reproduce:
Actual Behavior: The session does not persist across subdomains, requiring the user to sign in again on
Relevant Code/Configuration: My client-side code (using
Console logs confirm that
In the Supabase dashboard, under "Authentication -> URL Configuration", both
Key Finding (Network Tab): The critical observation from the network tab is that the
Example
This "host-only" cookie prevents it from being accessible on
Question: How can I configure my Supabase project or understand why the
Thank you
I am encountering an issue with cross-subdomain authentication for my application, which uses Supabase for user management. My goal is to achieve a single login session that persists across my main domain (
https://reirev.com) and its subdomain (https://app.reirev.com).Problem Description: When a user signs in on
https://reirev.com, the session is not recognized when they navigate to https://app.reirev.com. Instead, they are redirected back to the sign-in page on the subdomain, indicating that the authentication session is not being shared.Steps to Reproduce:
- Access the application at
https://reirev.com. - Open browser developer tools (e.g., Chrome DevTools) and navigate to the "Network" tab.
- Clear all network requests.
- Enter valid user credentials and click the "Sign In" button.
- Observe the network requests, specifically the one related to the Supabase authentication endpoint (e.g.,
toPOST/auth/v1/token). - Inspect the "Response Headers" for this request.
- Note the
Set-Cookieheader forsb-auth-token. - Navigate to
https://app.reirev.comin the same browser session. - Observe that the user is not authenticated and is redirected to the sign-in page.
- Check the "Application" tab -> "Cookies" for
https://app.reirev.com; thesb-auth-tokencookie is not present or not accessible.
https://reirev.com, the user's session should be recognized and persist when navigating to https://app.reirev.com, allowing for a seamless single sign-on experience across subdomains.Actual Behavior: The session does not persist across subdomains, requiring the user to sign in again on
https://app.reirev.com.Relevant Code/Configuration: My client-side code (using
@supabase/supabase-js) is configured to request the session cookie for the root domain. In src/lib/supabase.ts, the createClient call includes:Console logs confirm that
Auth cookie domain: .reirev.com is being passed to the Supabase client.In the Supabase dashboard, under "Authentication -> URL Configuration", both
https://reirev.com and https://app.reirev.com (along with http://localhost:3000 and specific reset password URLs) have been added to the "Site URL" and "Redirect URLs".Key Finding (Network Tab): The critical observation from the network tab is that the
Set-Cookie header for sb-auth-token returned by the Supabase server is setting the Domain attribute as reirev.com (without the leading dot), instead of .reirev.com.Example
Set-Cookie header observed: sb-auth-token=...; Path=/; Domain=reirev.com; Max-Age=2592000; HttpOnly; Secure; SameSite=LaxThis "host-only" cookie prevents it from being accessible on
app.reirev.com.Question: How can I configure my Supabase project or understand why the
sb-auth-token session cookie is being issued with Domain=reirev.com instead of Domain=.reirev.com from the server side, despite the client requesting the latter? Is there a specific setting in the Supabase dashboard or a known behavior for custom domains that needs to be addressed to ensure the cookie is issued for the root domain?Thank you