Open Closed

Replace Login Component not work with tenant #9991


User avatar
0
andmattia created

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)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent

    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:

    1. 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 your baseUrl 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 calling authService.navigateToLogin().

      Example:

    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 });
       }
    
    1. Backend Configuration:
      • Ensure your backend is configured to resolve tenants from the __tenant header or query string:
    Configure<AbpTenantResolveOptions>(options =>
         {
             options.AddHeaderTenantResolver();
             options.AddQueryStringTenantResolver();
             // Add domain resolver if using subdomains
         });
    
    1. Check Environment Configuration:

      • If you are not using domain-based tenant resolution, do not use {0} in your baseUrl. Instead, ensure the tenant is set in the session and passed during login.
    2. 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.

  • User Avatar
    0
    andmattia created

    With the proposal provided it still doesn't work

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.1.0-preview. Updated on October 14, 2025, 08:24