# Impersonation

In version 1.6 ([pull request](https://github.com/petalframework/petal_pro/pull/152)) we added the ability for admins to impersonate normal users.

<figure><img src="https://content.gitbook.com/content/jybnmx3gX5MSuPHDwIJB/blobs/BoSZyDeCxMKNgPEdxAke/Xnapper-2023-05-29-10.17.30.jpg" alt=""><figcaption><p>Admin can impersonate any normal user</p></figcaption></figure>

This adds two routes:

```elixir
post "/impersonate", UserImpersonationController, :create
delete "/impersonate", UserImpersonationController, :delete
```

Clicking the "Impersonate" button will perform a POST request to the above route, including the user\_id of the user to be impersonated. We store the `current_admin_id` in the session, and sign in the admin as that user.

Once the admin has finished, the sign out button will be replaced with an "Exit impersonation" button.

<figure><img src="https://content.gitbook.com/content/jybnmx3gX5MSuPHDwIJB/blobs/2oA4c34AXFbbWfVXmWHD/Xnapper-2023-05-29-10.22.45.jpg" alt=""><figcaption></figcaption></figure>

This button will hit the `:delete` action route, which looks for `current_admin_id` in the session and uses it to sign in to the admin user again.

#### Turn off impersonation

You can toggle impersonation on/off easily in `config.exs`:

```elixir
config :petal_pro,
  impersonation_enabled?: false
```
