How can I apply the latest multitenancy update to an existing app

Hi,
It was great to see the same user across tenants in the latest update. I tried overwriting security through the Studio, but it seems that the old unique constraint is still in the database which stops me from creating the same email in two tenants.

How should I apply the update to an existing app?

1.8.1

Multitenancy allows users with same name across tenants

Since the migration is already applied you should delete the index manually from your database:

Thanks, that let me create a new user with the same name in another tenant but it removed the roles from the original user and I get an error when I try to add the roles back to the original
image

The new user updates without an issue. Still looking....

I’m afraid I don’t know what this error means.

I couldn't find it in the code either, strange.

The error comes from the controller...

result = await userManager.RemoveFromRolesAsync(user, roles);

{Microsoft.AspNetCore.Identity.IdentityError}

Quick update... I am executing the user updates as the tenantsadmin on my localhost:5001. The user is in tenant localhost:5002 and it seems that the tenant is looked up taking the host and therefore returning the user from 5001 and not 5002 within userManager.

I found a hack/solution to make the username unique since this is what is throwing the error in identity.

Minor change in code for user creation...

var user = new ApplicationUser { UserName = $"{data.TenantId ?? 0}-{email}", Email = email, EmailConfirmed = true };

And fix the existing usernames in the database...

  update [AspNetUsers] 
  set UserName=cast(TenantId as nvarchar(10))+'-'+UserName,
  NormalizedUserName=cast(TenantId as nvarchar(10))+'-'+NormalizedUserName
  where TenantId is not null