Using the same project auth on sub domain and main domain #432
Replies: 1 comment
|
the session sharing happens because Supabase auth cookies default to the root domain scope. when both apps deploy from the same root domain, both apps see the same cookie and the sessions bleed into each other. the fix is to use different cookie names per app. the module derives the default cookie name from the Supabase project ref, so any two apps on the same project will collide by default. renaming the cookie per app gives each one its own isolated session. in your vendor app nuxt.config.ts: export default defineNuxtConfig({
supabase: {
cookieOptions: {
name: "sb-vendor-token",
maxAge: 60 * 60 * 8,
sameSite: "lax",
secure: true,
},
},
})in your main app nuxt.config.ts: export default defineNuxtConfig({
supabase: {
cookieOptions: {
name: "sb-main-token",
maxAge: 60 * 60 * 8,
sameSite: "lax",
secure: true,
},
},
})a user logged in on vendor.mywebsite.com will have a sb-vendor-token cookie, and a user logged in on mywebsite.com will have a sb-main-token cookie. they do not interfere with each other even though both apps talk to the same Supabase project and share the same underlying data. you do not need separate projects for multi-tenant setups. just distinct cookie names so each app manages its own session independently. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi, thanks a lot for this great library.
I have this problem I can't seem to figure out.
When I login on an account on my main domain, I am also logged out on my sub domain.
Is there a way to keep the domains seperated? I don't want to use different projects as data is shared across as my website is multi-tenant.
Say I have this domain and sub domain: mywebsite.com and vendor.mywebsite.com. I want to be able to log in with different account on these websites.
I have search and couldn't find any reliable solutions. Any have any idea on how to handle this case?
Thanks.
All reactions