Starts in:
1 DAY
15 HRS
4 MIN
38 SEC
Starts in:
1 D
15 H
4 M
38 S
Open Closed

Switching between abp tenants without logging in #1216


User avatar
0
kirtik created
  • ABP Framework version: v4.2
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes / no
  • Exception message and stack trace:
  • Steps to reproduce the issue:

We have a scenario where user1 and user2 have same usernames and same emailId . user1 username : ABC Password : 1q2w3E* email : abc@gmail.com TenantId : 1

user2 username : ABC Password : 1q2w3E* email : abc@gmail.com TenantId : 2

We want to implement in such a way that when user1 logs in to Tenant1 he can directly click on Tenant2 and login automatically through code and switch the context of Tenant1 to Tenant2. In the same way user can also switch back to Tenant1 .

We know about ICurrentTenant interface, but want to completely switch the tenants.

https://docs.abp.io/en/abp/latest/Multi-Tenancy#change-the-current-tenant

Is this possible in Abp.io ? If yes, please share the steps to achieving it..

This is high priority for the customer

Thanks


3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    This only works for MVC with no tiered project.

    var isPersistent = (await HttpContext.AuthenticateAsync(IdentityConstants.ApplicationScheme))?.Properties?.IsPersistent ?? false;
    await SignInManager.SignOutAsync();
    using (CurrentTenant.Change(user2.TenantId))
    {
        var user2 = await UserManager.GetByIdAsync(user2.Id.Value);
        await SignInManager.SignInAsync(user2, isPersistent);
    }
    
  • User Avatar
    0
    kirtik created

    Ok. We will soon try this approach and update you.

    Thanks !

  • User Avatar
    0
    kirtik created

    Hello @maliming ,

    Thanks a million ! This worked and solved a big hurdle for us !!

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06