How to authenticate users on a dynamic sudomain (next-auth)

Hey ! Hope you're doing well, I'm working on a project and I try to implement authentication on multiple domain with next-auth and Next.js Pages router. Here is a basic schema : - app.localhost:3000 (Admin only subdomain for managing the app, authentication needed) - [tenant].localhost:3000 (Authentication needed here using next-auth) Can someone help me with this. Currently, I got it working but I can't access session while i'm calling useSession from [tenant].localhost:3000. My NEXTAUTH_URL is http://app.localhost:3000
2 Replies
matthw g baller
matthw g baller10mo ago
my first initial thought would be cookies depending on how your cookies are set, i believe they aren't by default set to cover subdomains in your next-auth.config.js, change the sameSite setting to none, secure to process.env.NODE_ENV === 'production' and domain to '.localhost' and on the off chance it is not the cookies then make sure your NEXTAUTH_URL is set correctly
Alky
Alky10mo ago
You can also use a proxy page to login the user. I also have a multi-tenant app that, when the user login at the root domain, i redirect him to subdomain.website.com/proxy and re-do the login there automatically. Doing it right, the user doen't even see it. Create a one-use token, send it on the URL /proxy?token=yourtoken grab the token, do your auth, and the redirect to the app page
Want results from more Discord servers?
Add your server