Building an admin function to log in as a diferent user


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!