Next.js Discord

Discord Forum

Next Auth Multi Tenant Site

Unanswered
Exzotic posted this in #help-forum
Open in Discord
Hello! Im interested in building a "multi tenant" application with nextjs. I've seen this post: https://vercel.com/guides/nextjs-multi-tenant-application though im wondering how I would add authentication / login to the individual sites (the sites have its own users)? Would this be something possible with next auth?

16 Replies

^
Do you know any examples / tutorials on this?
Yes I have nextauth setup for the dashboard app though for users individual sites / domains, im not sure where to start?
So in theory I would need next auth on the [domain]/api/auth but how would I handle the credentials / callback urls?
or could I make something work on like a main "auth.MYDOMAIN.com" that the individual sites get the session from?
Anyone got any ideas?
Everybody avoiding this topic 👀
Barbary Lion
Are you wanting the URL to be reflecting the tenants company name ?

As apposed to when a user logs in, thjey are on app/dashboard?

I'm not entirely sure what you're asking / trying to do
Champagne D’Argent
For the sake of brevity & learning let’s assume tenants company name
Barbary Lion
on login (and probably some middleware to enforce it), redirect user to app/[tenant] where 'tenant' is the tenant's name retrieved from session info ? (coming from the cookie created at login)
@Barbary Lion Are you wanting the URL to be reflecting the tenants company name ? As apposed to when a user logs in, thjey are on app/dashboard? I'm not entirely sure what you're asking / trying to do
Yeah so like the app/dashboard is for managing their [tenant] site which has a login for that company. Then that companies tenant site has its own set of users for their site
If that makes sense
I do have a solution though im not sure if its a great one
(Discord OAuth)
A company / tenants user clicks on login on the app/[tenant] site which sends them to a discord oauth that redirects to my site auth.MYDOMAIN.com/?redirect={TENANTDOMAIN.COM/api/auth/callback} that then redirects it again to their site which should give the discord oauth user / details