# Building an admin function to log in as a diferent user

**URL:** <https://community.triggre.com/t/building-an-admin-function-to-log-in-as-a-diferent-user/748>\
**Category:** Data\
**Tags:** data, designer\
**Created:** [December 31, 2019, 11:00pm UTC](https://community.triggre.com/t/building-an-admin-function-to-log-in-as-a-diferent-user/748 "2019-12-31T23:00:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mar](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.triggre.com/mar/32/395_2.png) [@Mar](https://community.triggre.com/u/Mar)\
**Post date:** [December 31, 2019, 11:00pm UTC](https://community.triggre.com/t/building-an-admin-function-to-log-in-as-a-diferent-user/748/1 "2019-12-31T23:00:00Z")

</div>

## 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)](https://docs.triggre.com/tips-tricks/data-tips/splitting-users-and-persons).

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](https://docs.triggre.com/tips-tricks/data-tips/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_.  

3. Do the same for the _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.  

5. To prevent disputes later, it is a good idea to 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](https://canada1.discourse-cdn.com/flex035/uploads/triggre/original/1X/ccce793718d877f02757d9cde25e02fea349d2aa.png)

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.  

## 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.  

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](https://canada1.discourse-cdn.com/flex035/uploads/triggre/original/1X/e944b6e50d3f5ba3968379531db530b935e89093.png)

## 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!
