Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MostofaL's avatar

Seamless User Authentication and Registration in a Multitenant Laravel/Next.js App

I'm seeking a solution to achieve user authentication in a multitenant application seamlessly. Specifically, I want to log in or register users into my helpdesk app when they are already logged in on the tenant website, all without any noticeable user interaction.

Here's the setup: I've developed a helpdesk ticketing application using Laravel as the backend and Next.js as the frontend. The authentication process is managed by Sanctum (Airlock) between the frontend and backend.

In this multitenant setup, each tenant of the helpdesk application can have its own domain. They are identified based on their URL using the Stancl/Tenancy Package. Tenants can also point a subdomain (e.g., 'crm.tenant1.com') to the helpdesk frontend.

The issue arises when a user visits such a subdomain. They are prompted to log in or register again inside the helpdesk app, even though they are already logged in on the tenant website.

My goal is to make this login or registration process happen seamlessly in the background. If a user is already logged in on the tenant website, they should automatically be logged into the tenant when visiting 'crm.tenant1.com'. If it's their first time and the user doesn't exist in the helpdesk database, it should request their user data from 'tenant1.com', register the user, and log them in without their awareness.

I want users to feel like they are simply navigating to another page within 'tenant1.com' when they visit 'crm.tenant1.com'.

Can you provide guidance on how to achieve this? Is it possible with Sanctum, or do I need another package? What are the best practices for implementing this seamless authentication and registration process? Your insights and recommendations would be greatly appreciated.

0 likes
1 reply
jlrdw's avatar

You could perhaps have some added fields to hold a temporary key or token based on their login and use that.

However many sites I use, both Acronis True Image, Macrium Reflect, etc have separate logins for a different part of the site which is normal. Like Macrium Reflect has a separate login for the forum and to submit a ticket.

Just something to think about.

Otherwise you could hold their submitted credentials in session and use them to login to the help desk.

Better yet why not integrate help desk code to Auth. I mean do you have already a common User table. So apply authentication like you would for any section of an app.

Please or to participate in this conversation.