The problem is that when I set the tenant and click Login, it always tries to log in as the host. It doesn't seem to pass the tenant. I followed this git to replace the components.
https://gist.github.com/mehmet-erim/dac82931935a465a48802447de501032
My environment.ts is
import { Environment } from '@abp/ng.core';
const baseUrl = 'http://localhost:4200';
const oAuthConfig = { issuer: 'https://...../', redirectUri: baseUrl, clientId: 'Angular', scope: 'offline_access address roles openid profile email phone AuthServer IdentityService AdministrationService AuditLoggingService GdprService SaasService LanguageService OfficeService', requireHttps: false, impersonation: { tenantImpersonation: true, userImpersonation: true, } };
export const environment = { production: false, googleMapsApiKey: 'AIzaSyBsYU6NzW63ZGx_l3vDvtPsQ-ix_NHgPtI', application: { baseUrl, name: 'routilia', }, localization: { defaultResourceName: 'routilia' }, oAuthConfig, apis: { default: { url: 'https://.......', rootNamespace: 'dm.routilia', }, // OfficeService: { // url: 'http://......', // rootNamespace: 'dm.routilia', // }, AbpAccountPublic: { url: oAuthConfig.issuer, rootNamespace: 'AbpAccountPublic', }, }, } as Environment;
2 Answer(s)
-
0
To ensure the tenant is correctly passed during login in an ABP Angular application, you must configure both the backend and frontend to resolve and transmit the tenant information. If you replace the login component but do not handle tenant resolution and transmission, the login will default to the host.
Solution Steps:
Frontend (Angular) Configuration:
- The Angular app must send the
__tenant
header with each request. This is handled automatically if you use the{0}
placeholder in yourbaseUrl
and configure the backend for domain/subdomain tenant resolution. - If you are not using domain-based tenant resolution, you must ensure the login component sets the tenant explicitly. Use the
SessionStateService
to set the tenant before login, or pass the__tenant
parameter when callingauthService.navigateToLogin()
.
Example:
- The Angular app must send the
import { AuthService, SessionStateService } from '@abp/ng.core'; // ... constructor(private authService: AuthService, private sessionState: SessionStateService) {} login() { const tenantId = this.sessionState.getTenant().id; this.authService.navigateToLogin({ __tenant: tenantId }); }
- Backend Configuration:
- Ensure your backend is configured to resolve tenants from the
__tenant
header or query string:
- Ensure your backend is configured to resolve tenants from the
Configure<AbpTenantResolveOptions>(options => { options.AddHeaderTenantResolver(); options.AddQueryStringTenantResolver(); // Add domain resolver if using subdomains });
Check Environment Configuration:
- If you are not using domain-based tenant resolution, do not use
{0}
in yourbaseUrl
. Instead, ensure the tenant is set in the session and passed during login.
- If you are not using domain-based tenant resolution, do not use
Disable Tenant Switcher (Optional):
- If you want to prevent users from switching tenants, hide or remove the tenant switcher component from your login UI.
Summary:
- Use
SessionStateService
to set/get the tenant. - Pass the tenant to
navigateToLogin
as shown above. - Ensure backend resolves tenants from headers or query string.
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
With the proposal provided it still doesn't work