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.