Centralized Auth with Better Auth Across Multiple Domains – CORS Issues
Hey! I’m using the Better Auth framework in a Next.js dashboard app. I’m now splitting the app into three separate dashboards across different domains and want to use a single server for authentication.
However, I’m running into CORS issues. The simplest workaround seems to be running auth separately in each project, but that feels redundant. Has anyone dealt with this and found a clean, centralized solution? Appreciate any insights!
13 Replies
What backend are you using?
Just using next.js api routes for the auth, as per this doc https://www.better-auth.com/docs/integrations/next
Next.js integration | Better Auth
Integrate Better Auth with Next.js.
Oh, then i can't really help. For next.js maybe it would be better to just do the backend 3 times i guess?
Doing a separate backend for this would be ideal, better auth provides you with cross domain cookies etc. And you could set up CORS just as easily.
use domain as '.domain.com' in cookie, advanced and crossSubDomain
Yeah, had the same thought, it's just a little friction to have another service for it, but seems like that's the way to do it
Could you elaborate, or point to a text that talks about this? Thanks 😇
Cookies | Better Auth
Learn how cookies are used in Better Auth.
Thanks!
it's like this
Thanks! I’m not very experienced with auth, so I’d love your take — do you think it’s better to have a separate auth server, or host auth under one of the dashboard domains?
host auth under of the dashboard domain
if you have more bigger project then implement separate make sense but for smaller project hosted under one is enough
also implement trustedOrigin
Ok thanks! And with "bigger project", you mean in terms of users or codebase size?
in term of different services you provide
like google where it has multiple project but one auth server can be used for all the other apps in google workspace
ah yes ok, makes sense. Thanks!