Base solution for your next web application
Open Closed

Setting TenantId after authentication of the user. #2850


User avatar
0
codenewa created

Is it possible to set the tenantId after the user has logged in?


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

    Hi,

    This is possible but it will cause some problems. Can you explain your use-case a litttle bit more so we can have a better idea ?

    Thanks.

  • User Avatar
    0
    codenewa created

    Currently, there are two ways of logging into the system for the multi tenant applications.

    1. Use subdomain routing to identify the tenant.
    2. If we do not use subdomains for routing, then the user has to provide the tenancy name on the login screen to identify the tenant.

    We want to be able to login to the application from the same login screen. Since the user is tied to a tenant, it should be possible to set the tenant after authenticating the user. Is that right?

    We don't plan on using separate databases for the tenants.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    In your project you can override LoginManager's LoginAsyncInternal method and set tenant after finding user. See <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero/blob/master/src/Abp.Zero/Authorization/AbpLoginManager.cs#L73">https://github.com/aspnetboilerplate/mo ... ger.cs#L73</a>

  • User Avatar
    0
    codenewa created

    Thank you. I'll take a look at it.

    You mentioned before that there might be some issues when we set the tenantid after completing the authentication. Can you tell me what they are?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    It was related to DB per tenant, as you can guess it is not a problem in your case.

  • User Avatar
    0
    codenewa created

    I'm looking at it now. But I'm not sure how to query across the tenants. Do you have documentation on that?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can disable the tenancy filter and query all users, see <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Data-Filters#DocDisableFilters">https://aspnetboilerplate.com/Pages/Doc ... bleFilters</a>.

    Thanks.

  • User Avatar
    0
    codenewa created

    Thank you that worked.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Great :).