I don't think I described the problem properly through the title. However, I have a .NET Core Web Api application which all of my tenants will use. As well as the single API instance I have a single frontend Vuejs instance which all tenants can use as a 'portal'.
These tenants each have their own database. Currently the api's all require a header of tenant
within a request to specify which tenant the request is being made for, this will then create a db connection according to the tenant from the request.
You can't pretend your a different tenant as all of the api's require authorization against a tenants db.
I guess the thing I'm stuck on is determining the tenant a user belongs to when logging in using the single frontend vuejs instance. It's not a problem when it comes to just using the api's as the tenant can be sent via the header of the request, but im not sure how to resolve the tenant in order to determine the correct db to use by a sign in which will be used across all tenants.
Apologies if I didn't explain the problem well, it's a tricky situation.
where are your users live? You might have to extract users info into a separate identity database that contains info which user belongs to which tenant. That can be as simple as Key-Value store: email->TenantId. So for login you'll have to look up this tenantId
, then authenticate against user info in the correct tenant database.
Or you can pull all your user information into a single database that contains all the info about the user, including password hash. You can also use some identity provider like Auth0 or IdentityServer - these have ability to add user properties like TenantId
.
Whatever the scenario you choose, you'll have to have a single place where you map user to a tenant. Looking through multiple databases for user info is not ideal.
If your Vue.js app is using your backend API you can set TenantId in cookie or other way to persist this info between calls.