I’ve built an application using a multi-tenant architecture. To handle tenant-based database switching, I’ve implemented a custom router and middleware.
In the Django admin panel, I’ve added a dropdown for tenant selection alongside the username and password login. Upon selecting a tenant, an API call is triggered to set the selected tenant in the session. This allows me to log in and access the selected tenant’s data.
However, I’m facing an issue: although I can log in successfully with the selected tenant, I’m intermittently logged out when navigating through menus or performing certain actions in the admin panel. After some debugging, I noticed that in some cases, the sessionid
is being set to null
, which leads to an automatic logout.
My question is:
Is this an appropriate or recommended approach for implementing multi-tenancy in the Django admin panel? If not, what would be a more reliable method to handle tenant switching and session management in this scenario?