Building an admin function to log in as a diferent user

Introduction

If users have questions or encounter problems, the helper sometimes can understand the user better when he can see exactly the same as the user. You can achieve this by taking over the account of the user.

The prerequisites are that your application contains the Data items User and Person (check the article about splitting users and persons for an explanation).

What will happen:

  1. In order to recreate the situation when the helper is finished, the Persons who are the owner of the accounts must be saved in the Data item User.

  2. After that, the application links the Person that will be taken (the Helped person) over to the user-account of the helper.

  3. This means that while the Person is taken over, he can remain signed in or sign in during the operation, but he can’t see his person-related data.

  4. The helper remains signed in with his own account, so he has his own Roles, but he can’t see his personal data.

  5. The helper can see the data of the Helped person and he can act as if he were him.

  6. Afterwards, the original relations between the user accounts and Persons that ‘own’ them are restored.

Step 1: split users and Persons

If you haven’t done this yet, refer to the article “Splitting users and persons” in our Knowledge base.

Step 2: modify Data item User

Add the True or False Property May take over persons.

Note: you might already have the Property Is admin. Don’t use this: the Persons who will be allowed to take over a client might not all be admins.

Step 3: create the Flow part to take over a Person

  1. Add 2 Inputs: the Helping user and the Helped user.

  2. When you have finished helping, you want to restore the situation. Therefore you must save the owner of the helped account in Person that owns the account.
    Person selection for helped user

  3. Do the same for the Helping user.
    Person selection for helping user

  4. Now the original owners of the accounts are safely stored, you can link the Helping user account to the owner of the Helped user account.
    Link helping user
    Link helping user

  5. To prevent disputes later, it is a good idea to add the action to a log.
    Add the action to a log

Step 4: create the Flow part to restore the situation

  1. Add 1 Input: the Helping user.

  2. Check if the Account owner of the Helping user is Empty. If so: the Helping person is not taking over a Person. End the flow.

  3. If there is a value in Owner, find the user account of the Helped person (the person that owns the account of the Helped user = the Person in the account of the Helping user).
    Person that own the account set up

  4. Copy the Owner of the helped account to Person of the helped account. Now the Helped user and his account are linked again.

  5. Clear the Owner of the helped account. This is the signal that the user is not being helped.

  6. Copy the Owner of the helping account to Person of the helping account. Now the Helping user and his account are linked again.

  7. Clear the Owner of the helping account. This is the signal that the user is not helping.

  8. To prevent disputes later, it is a good idea to add the action to a log.
    Add the action to a log

Step 5: modify User flows

Modify the User flow Persons:

  1. In the User flow where you manage the Persons, include a Button that is only visible when the Property May take over persons in User is True.

  2. This Button calls the Flow part Take over a person, followed by a Page on which you tell the user what just happened.

  3. Add the Button Got it that connects to the User flow My profile or another one that the person normally opens.

  4. Insert the Flow part When needed split helper and helped person right after the start of the User flow. This will restore the situation.
    Flow part insertion

Sometimes helpers forget to restore the Take-over situation by returning to Persons. This can lead to unwanted situations.

Therefore, it is advised to include the splitting Flow part at least in the first User flow the user will see when they log in. This way, the application checks if there is a helping situation going on and it can end it when the helper has left the User flows of the Helped person.
Splitting flow part inclusion

How to check for irregularities

It can happen that a take over is not flawlessly restored. This leads to the situation that a user can’t reach his data. We advise you to store a copy of the User email in the Data item Person. This makes it easier to find the ‘lost’ user account of the person.

Once you have done that, you can search for Persons whose email address differs from the linked user account, or active users who are not linked to a person.

You can perform these searches manually, for instance by including it in your User management flow.

Tip: By following these steps you’ll soon be an application building guru!