Base solution for your next web application
Open Closed

How to bypass initial tenant selection #12351


User avatar
0
uenlkr4e created

Hi,
Is there an easy way to bypass the initial tenant selection?
I dont want to use subdomain structure either.
I have multi tenant enabled but they are all in the same db, so I want to set the first tenant as default tenant for the logged in user without having him select a tenant initially.

Any pointers will be greatly appreciated.
thank you


9 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @uenlkr4e

    You can configure this to use different databases for tenants, and you need to set this up when creating the tenant. If you want to specify a default tenant for a user who logs in, you can set the TenantId to a default tenant when the user registers.

  • User Avatar
    0
    uenlkr4e created

    This isnt exactly what i need.
    I want to keep all tenants in the same db but i dont want a user to select his tenant before the login operation.
    isnt this possible?

    system will find users default tenant at the time of the login and run with that tenant.

    I understand that selecting a tenant before login makes sense if tenants use different databases but for me this isnt the case. and my users are asking "why do i have to select a tenant before login, cant i just login".

    there has to be a way to make it easily possible but i dont know where.

    thank you

  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @uenlkr4e

    You can implement this scenario as follows: In multi-tenancy enabled applications, users other than the host users require a tenant. Therefore, for users who do not want to select a tenant, you can create a separate login page or remove the tenant selection part from the current login page. Then, you can manually set a default tenant for the user logging in. This way, you will hide the tenant structure, allowing the user to log into the application without selecting a tenant.

  • User Avatar
    0
    uenlkr4e created

    Hi,
    Where do i manually set the default tenant for the user?
    The code there is fairly complex and I dont want to ruin something while setting a tenant manually in the wrong place.

    thanks

  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @uenlkr4e

    To better assist you, is your project using Angular UI or MVC UI?

  • User Avatar
    0
    uenlkr4e created

    angular ui

  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @uenlkr4e

    You need to make changes to the save function in the tenant-change-modal component. You can set the tenant information using the abp.multiTenancy.setTenantIdCookie() method. When a user registers or logs in, the tenant information is retrieved from AbpSession and processed accordingly.

    While modifying the save function, keep in mind that the tenant information should be set to null for the host user. To handle this distinction, you can use a separate page for the host user or modify the existing page so that during tenant selection, it only allows tenant or host switching without requiring the tenant name information.

  • User Avatar
    0
    uenlkr4e created

    Hi,
    I havent done this yet but it is a "must have" requirement now.
    I understand that i have to remove the tenant name box from the login page, but i will still keep the host/tenant switch.

    The part i dont understand is setting a default tenant for the user. what if the user does not belong to this default tenant?

    Say i have tenantA, tenantB, and tenantC.
    The user of tenantB tries to login: enters username and password but there is no tenantId set at this point because i dont know which tenant the user belongs to.
    What am i supposed to do at this point?

    thanks in advance

  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @uenlkr4e

    If the user is not associated with any tenant, it will be the Host user. If you want to disable the tenant selection on the login screen here. And if you want to use the tenant structure, you need to specify the Tenant when registering or creating this user. Since the queries are made according to the filtering structure, since the tenant user does not specify the tenant on the login screen, you need to specify this in the background before the login process.

    When performing user validation for the login process, you will need to disable the tenant filter and retrieve user information from all users. Afterward, you should set the user's tenant. This way, you won't need to disable the tenant filter in subsequent queries.