How to Hide Tenant Selection in the login screen & handles tenant resolving in the backend by username
5 Answer(s)
-
0
To hide the tenant selection on the login screen and resolve the tenant by username in the backend for an ABP Angular UI (v9.0.4, non-tiered), follow these steps:
Remove Tenant Selection from the Login UI
- In Angular, the tenant switch is typically shown based on the multi-tenancy configuration. You can hide the tenant input by customizing the login component template to remove or hide the tenant field.
Backend: Resolve Tenant by Username
- Override the login logic on the backend to determine the tenant based on the username or email address provided. This involves:
- Searching for the user across all tenants.
- Once the user is found, set the current tenant context before proceeding with authentication.
Example implementation (in your AccountController or a custom login service):
- Override the login logic on the backend to determine the tenant based on the username or email address provided. This involves:
public class CustomLoginModel : LoginModel { private readonly ITenantRepository _tenantRepository; public CustomLoginModel( IAuthenticationSchemeProvider schemeProvider, IOptions<AbpAccountOptions> accountOptions, IOptions<IdentityOptions> identityOptions, ITenantRepository tenantRepository, IdentityDynamicClaimsPrincipalContributorCache contributorCache) : base(schemeProvider, accountOptions, identityOptions, contributorCache) { _tenantRepository = tenantRepository; } public override async Task<IActionResult> OnPostAsync(string action) { var user = await FindUserAsync(LoginInput.UserNameOrEmailAddress); using (CurrentTenant.Change(user?.TenantId)) { return await base.OnPostAsync(action); } } protected virtual async Task<IdentityUser> FindUserAsync(string uniqueUserNameOrEmailAddress) { IdentityUser user = null; using (CurrentTenant.Change(null)) { user = await UserManager.FindByNameAsync(LoginInput.UserNameOrEmailAddress) ?? await UserManager.FindByEmailAsync(LoginInput.UserNameOrEmailAddress); if (user != null) { return user; } } foreach (var tenant in await _tenantRepository.GetListAsync()) { using (CurrentTenant.Change(tenant.Id)) { user = await UserManager.FindByNameAsync(LoginInput.UserNameOrEmailAddress) ?? await UserManager.FindByEmailAsync(LoginInput.UserNameOrEmailAddress); if (user != null) { return user; } } } return null; } }
- This code searches for the user in the host and all tenants, and sets the tenant context accordingly.
Ensure Usernames/Emails are Unique Across Tenants
- This approach requires that usernames or emails are unique across all tenants.
No Tenant Input on Frontend
- The Angular frontend should only ask for username/email and password.
With this setup, users log in with just their username/email and password, and the backend determines the tenant automatically.
Sources:
This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.
-
0
my login page is MVC, the auth flow is codeflow when user try to login angular app redirect to Login Page MVC on backend side
-
0
hi
1.
Removing
QueryStringTenantResolveContributor
andCookieTenantResolveContributor
will hide the tenant selection in the login page.Configure<AbpTenantResolveOptions>(options => { options.TenantResolvers.RemoveAll(resolver => resolver is QueryStringTenantResolveContributor or CookieTenantResolveContributor); });
2.
If you don't want to remove them, you can override the MVC theme account layout page.
see https://github.com/abpframework/abp/blob/dev/modules/basic-theme/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Account.cshtml#L70-L72
Thanks.
-
0
Configure<AbpTenantResolveOptions>(options => { options.TenantResolvers.RemoveAll(resolver => resolver is QueryStringTenantResolveContributor or CookieTenantResolveContributor); });
Hide them but how tenant will be resolved for the loggedIn user should i create custom tenant resolver or should i create custom login to customize login process ? -
0
hi
should i create custom tenant resolver or should i create custom login to customize login process ?
Both are ok.
You can switch the tenant by override the Login page.
Or add a new
MyTenantResolveContributor
, and try to get request info to determine the current tenant.Thanks,