26
Views
5
Comments
how to add a user to a particular tenant?

Hello,

         This multitenancy feature is so confusing. I've created two tenants in service center of my app. I also created two users. How to assign a user to a particular tenant? Like if I log in with user1 creds tenant 1 data should be displayed and same should happen with user2. Also can anyone please explain me thefunctionality if tenant switch and how it works and also  the below statement.

  • User_Login: The User_Login action of the default Users application automatically binds an end-user to the correct tenant. If the login is successful, all queries are automatically filtered to only return data from the tenant;


Regards

Vaishnavi

mvp_badge
MVP
Rank: #72

Hi Vaishnavi,

I would like to suggest to go through these learning materials in order to understand the concept of multitenancy.

Also, there is a Multitenant Management application available in the Forge, which you can use as reference.

Hope this helps.

Regards,

Nordin

mvp_badge
MVP
Rank: #72

Hi Vaishnavi,

I'm not sure I understand the exact issue you are facing.

If you want to create a specific user for a specific tenant, the Multitenant Management application enables you to do just that.

As you can see in the below example, I have just created the user 'SSadmin' for the Service Center tenant (which has TenantId = 1). Notice that the screens have a TenantId input parameter that allows data isolation for a specific tenant.

After that, I went and logged in Service Center with the 'SSadmin' user and the password I created using the Multitenant Management application.

When you look at the code of the Multitenant Management application, notice that the User entity and other related entities have their Tenant Identifier exposed. If you double-click the User entity and go to the Advanced tab, you notice the Show Tenant Identifier checkbox is checked. As a result, an extra column to the left named Tenant_Id was added to the User entity. As a result, the automatic data isolation for this entity is disabled and all the User data across all tenants can be viewed and managed within this application.

Notice that the first row contains the 'SSadmin' user we have created in the above example for the Service Center tenant (Tenant_Id = 1). 

You can do the same and manage all the users for other tenants that you have created with the use of this application.

Hope this makes it more clear.

Regards,

Nordin

mvp_badge
MVP
Rank: #72

Hi Vaishnavi,

Do you mean you have created an extra tenant for the Users module via Service Center like in the below example?

If this is the case and you try to login with that user you have created for the new tenant, the User Provider for the module you try to login to has to be Users.

What I did is I have created a 'testuser' for the previously created 'TestTenant' inside the Multitenant Management application. 

Then I have started a debug session while login in with this 'testuser', to demonstrate the automatic binding of an end-user to the correct tenant and to come back to this statement on the Users_Login action you shared in your first post.

  • User_Login: The User_Login action of the default Users application automatically binds an end-user to the correct tenant. If the login is successful, all queries are automatically filtered to only return data from the tenant;

As you can see I have set a breakpoint before the User_Login action and at this point the TenantId = 20 which is the Identifier of the Users Tenant (which is the Default Tenant of the Users module as you can see in the Service Center snapshot).

I have set another breakpoint after the User_Login action and you can see that the Tenant has automatically switched to the newly created 'TestTenant' where the 'testuser' was created under.

As a result, I am logged in under the TestTenant.

Let me know if it helped.

Regards,

Nordin