PaulDiamant's avatar

Multiple authentication across subdomains

I'm creating an ecommerce platform where users can make their own shops and get a subdomain. Laravel can handle authentication but how will I go about handling authentication in different sub domains? So each subdomain has its own session and there's one table of users for all stores globally.

0 likes
2 replies
mushketer888's avatar

Short advice.Add column to users-subdomain(string). Get subdomain from Request facade/object (maybe use regexp). Override Auth controller, add there where('subdomain,'=',... .But it means every table must have subdomain column. Or column with subdomain_id. Middleware somehow can help you maybe also. You can make Helper which gives you subdomain and use it in Models with where() function => simplest method.

martinbean's avatar

@PaulDiamant Laravel will do this out of the box. Cookies are scoped to the top-level domain, so users will need to log in individually on each sub-domain.

1 like

Please or to participate in this conversation.