Cookies amongst multiple tenants, subdomains, and custom domains for a SaaS
Hey folks, I'm working on what is ultimately Squarespace for a niche, where users will get a unique subdomain, and can also add their own custom domain (so we have
mycoolapp.com
where i'll be serving the marketing, john.mycoolapp.com
, and maryscoolapp.com
).
Looking for guidance on how to get it working with BetterAuth; my stack is SvelteKit, with Postgres + Drizzle (using the direct Postgres connector, though), with Directus as the CMS for end users. Currently I'm having an issue where the cookies are being set on the TLD and not working on the subdomains.
I'm aware that there's an organisation plugin, but that doesn't look to have anything specific to sharing cookies between sites.5 Replies
req headers for sign-up via email:
response headers:
PUBLIC_DOMAIN
is https://localhost:5173 and PUBLIC_COOKIE_DOMAIN
is localhost:5173
I have been working on a similar project..it's in next js...to implement tenant specific authentication..I took inspiration form vercel platform starter kit ..however I am stuck on how to do authentication for tenants customers...just asked for help here also some times back..anyway you could do something similar for your app...you can implement auth directly on
subdomain.maindomain.com
....I could not figure out either how to make crossSubdomainCookies
work properly..Good to know we have the same problem. Hopefully there's an easy fix!
I don't think there is any for my usecase (ping confirmed) ..but in your case you if you are not concerns about your tenants users..you can use the work around I have described above...for code example just check the vercel platform stater repo
Hey guys, did you manage to solve this? I'm trying to get subdomain based multi-tenancy working using the organization domain field from DB as subdomain/domain. This seems like it would be a common approach to multi tenancy.