Base solution for your next web application
Open Closed

Unique email address for all tenants #123


User avatar
0
valeriy created

Hi. How can I check that email is not registered If app uses multi-tenancy? _userManager.FindByEmail(loginModel.EmailAddress) return null if user has tenantId =2. It's need if user forgot his password. Thanks


4 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    If user not logged in, then system works in host mode for IMayHaveTenant filter. So, when you searcy by email, it tries to find from host userts, not the tenant 2.

    There are 2 solutions:

    1. If you know TenantId/TenancyName somehow, then you can set tenantId filter parameter before using FindByEmail as shown below:
    CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, 42);
    
    1. if you don't know tenantId then disable IMayHaveTenant filter (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Data-Filters#DocDisableFilters">http://www.aspnetboilerplate.com/Pages/ ... bleFilters</a>) and use UserManager.Users.Where(...)... to find user by email. But, in this case you can find more than one user with same email in different tenants.

    If you really want email uniqueness system-wide, you can write some custom code before user registration (or override UserManager.CreateUserAsync and check it).

  • User Avatar
    0
    girish28892 created

    @hikalkan i hav put filter its giving me error "Object reference not set to an instance of an object."

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Where did you use this code ? I think it's in a non unitOfWork method and because of that CurrentUnitOfWork is null in your case.

  • User Avatar
    0
    girish28892 created

    <cite>ismcagdas: </cite> Hi,

    Where did you use this code ? I think it's in a non unitOfWork method and because of that CurrentUnitOfWork is null in your case.

    fixed...thanks alot