# 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="/files/OChtUjWXZtcPG425AgBi" 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="/files/fJ5AwxjwnUVfeZZ6xI1F" 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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.petal.build/petal-pro-documentation/v1.7.0/fundamentals/impersonation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
