Viewing latest docs.
Switch version: v3

Impersonation

Admins can sign in as any user

In version 1.6 (pull request) we added the ability for admins to impersonate normal users. From the admin panel, admins can impersonate any normal user. This adds two routes:

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 admin’s id in the session as :impersonator_user_id, 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.

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

An admin has to finish signing in before they can impersonate. Since 4.5.2, an admin who has typed their password but still owes a two-factor code or passkey is sent to that step instead. Before 4.5.2, impersonating and switching back skipped the second factor, so a password alone gave a full admin session.

Turn off impersonation

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

config :petal_pro,
impersonation_enabled?: false