Auth with multiple subdomains
Unanswered
Citrine Wagtail posted this in #help-forum
Citrine WagtailOP
Hi,
I'm currently using Lucia for a Next app, and I'd like to add multiple subdomains to the app, and keep one auth method. I want to keep everything inside one Next project, is this doable?
I am hosting on a VPS, not Vercel.
I'm currently using Lucia for a Next app, and I'd like to add multiple subdomains to the app, and keep one auth method. I want to keep everything inside one Next project, is this doable?
I am hosting on a VPS, not Vercel.
9 Replies
Toyger
depends on what functionality you need, problem can be sharing cookies, iirc correctly cookies set on main domain will be shared to subdomain but not in opposite way.
@Toyger depends on what functionality you need, problem can be sharing cookies, iirc correctly cookies set on main domain will be shared to subdomain but not in opposite way.
Citrine WagtailOP
Currently I have one site, but I want to add a subdomain for a second event. I want to share logins (so if you log-in on the page1, you are logged into page2 as well).
And I want to keep everything in one next app - I can't really find anything regarding routing for specific subdomains.
@Citrine Wagtail And I want to keep everything in one next app - I can't really find anything regarding routing for specific subdomains.
Toyger
for routing it's easiest task, you can check headers origin or referer or x-forwarded-host, and you'll get current domain and do whatever you want with it, like render different components for different domains.
but as I am saying problem can be with auth, you'll probably need some workaround that will set cookies and maybe even localstorage for different domains, one of the ways is iframe, or cors request.
but as I am saying problem can be with auth, you'll probably need some workaround that will set cookies and maybe even localstorage for different domains, one of the ways is iframe, or cors request.
Citrine WagtailOP
Ugh, I wanted to avoid that. Could I somehow utilize this property?
https://lucia-auth.com/basics/configuration/#csrfprotection
https://lucia-auth.com/basics/configuration/#csrfprotection
@Citrine Wagtail Ugh, I wanted to avoid that. Could I somehow utilize this property?
https://lucia-auth.com/basics/configuration/#csrfprotection
Toyger
no, it still persist session in cookies on client side, and it will be set on current domain only
Citrine WagtailOP
Hm, I see. Although if I put everthing on a slug like domain.com/something, it would work. Maybe I'll just go for that.
Is there something I'm missing here? I would assume I'm not the only one with this approach.
@Citrine Wagtail Is there something I'm missing here? I would assume I'm not the only one with this approach.
Toyger
as I said if you'll login users through main domain then it should work on subdomains, at least cookies side, maybe there will be some changes in lucia if they specific domain cookies only.