| Posted by: WUICTeam - Wednesday, November 18, 2026 9:01:42 AM |
|---|
| [b]Question[/b] A user exists only in the metadata DB of one tenant, not in the primary one. How does the login find the right tenant, and what must I set up so it works? [b]Answer[/b] Through the [c]_login_index[/c] table on the primary metadata DB: you have to register the username there with [c]sp__login_index_upsert[/c], otherwise the login stops at the primary DB and fails with invalid credentials. [b]How it works[/b] The login first looks for the user on the primary metadata DB. Only on a miss, and only with [c]multiConnectionEnabled[/c] on, the backend computes the SHA-256 of the lowercased username, reads the matching [c]id_azienda[/c] values from [c]_login_index[/c] (ascending order) and retries the login on each tenant's metadata DB. The first tenant that validates the password wins, and the cookie is issued with that tenant's [c]azienda_id[/c]. Because the hash is computed on the lowercase username, [c]Mario.Rossi[/c] and [c]mario.rossi[/c] hit the same index row. Creating the user in the tenant DB does not fill the index, so after creating it run: [code]EXEC [dbo].[sp__login_index_upsert] @username = N'mario.rossi.t1', @idAzienda = 1;[/code] (on MySQL, PostgreSQL and Oracle the same procedure is called with [c]CALL[/c]). [b]If the login still fails, check[/b] [list] [*]the company row in [c]Aziende[/c] has [c]Valida[/c] = 1 and both [c]Connessione_DB_Dati[/c] and [c]CONNESSIONE_DB_Meta[/c] filled: a company that does not satisfy this is not in the tenant map and its candidate is skipped. [*]those two columns hold the [i]name[/i] of an entry in [c]ConnectionStrings[/c], and that entry exists in the appsettings of the running backend. [*]the tenant DB is reachable: a connection error on one candidate is swallowed and the next one is tried, so you only see the generic invalid-credentials result. [*]you changed [c]Aziende[/c]? The tenant map is cached: run [c]invalidateMetadataRuntime[/c] with [c]clearAll[/c] true. [/list] [b]Avoid[/b] The same username on two tenants: the user always lands on the lowest [c]id_azienda[/c] whose password matches. Use distinct usernames per tenant. [url=https://wuic-framework.com/docs/multi-tenant]Documentation: Multi-tenant[/url] |