How to get a function callback for baseurl or crossSubDomainCookies.domain
I have Better Auth backend for multiple websites:
-1) appA.example1.com and appB.example1.com using the same authentication.
-2) appA.example2.com and appB.example2.com using the same authentication.
I want to put the cookie for 1) on domain example1.com, and for 2) on domain example2.com
How to have a function callback for baseurl or crossSubDomainCookies.domain so that I can put the cookie domain to the right value>
Alternatively, a regex for crossSubDomainCookies.domain consisting of suppressing the subdomain.
Thank you for your help in advance.
There is an issue opened on Github but the automatic bot is out of control:
https://github.com/better-auth/better-auth/issues/4151
GitHub
Dynamic setting of
baseURL based on current request · Issue #415...An app could be running on ten different URLs at the same time. e.g. an app deployed on Vercel might have a couple of custom domain names, deployment id sub domain, and environment sub domain. It&#...
4 Replies
I must be misunderstanding this a little bit - and have just started exploring better-auth -- but isn't the method to acccess cookies on subdomains be setting the domain to
.example.com (don't forget the preceeding '.') ?
Have I misunderstood?
So for example1.com you would set the cookies from appA and appB on .example1.com and so onIt's the backend which sets the cookie. For appA.example1.com, it will set to .appA.example1.com. I can definitely put crossSubDomainCookies.domain to "example1.com" and then the cookie set up by the backend will be .example1.com indeed. This will work for appB.example1.com.
But the SAME backend also deals with example2.com for which I want domain = "example2.com"... Hence the problem.
Also, I'm not interested to have a dynamic callback for baseurl because my whole architecture is proxied.
What I really want is a function callback for crossSubDomainCookies.domain that gets the current url as argument so that i can derive the cookie domain from the url (*.example1.com -> example1.com and *.example2.com -> example2.com) or to get some kind of regex rule for crossSubDomainCookies.domain.
Oh I see. Sorry not familiar with this so don’t really have any authority / knowledge to answer properly
So in your backend / better auth, you’re able to set the domain .example1.com or .example2.com based on where the request is coming from??
Your proxy not passing the $host / $server_name to your backend?
Sorry.. I’ll let someone else answer.
no, you can't set crossSubDomainCookies.domain with different values. That's the whole problem...