ExAdmin v0.8.3-build.2 ExAdmin.Plug.SwitchUser

Allow users to switch to a different login.

Adds a drop down menu item on the page header with a list of all users. Selecting a user, automatically logs out the current user and logs in the selected user.

The login is automatic without requiring a password to be entered.

Use of this feature should be restricted to dev and test environments.

Configuration

add the following to your project’s config/dev.exs file

config :ex_admin_runtime,
  logout_user: {Coherence.ControllerHelpers, :logout_user},
  login_user: {Coherence.ControllerHelpers, :login_user}

add the following to your web/route.ex file

pipeline :protected do
  plug :accepts, ["html"]
  # ...
  if Mix.env == :dev do
    plug ExAdmin.Plug.SwitchUser
  end
end

by default, the user’s name for each entry in the drop down list is fetched with the :name field of the user schema. See the following for examples on how to change this default:

# change the field in `config/dev.exs`
config :ex_admin_runtime,
  current_user_name: :full_name,
  current_user_name: &MyProject.User.user_name/1,
  current_user_name: {MyProject.User, :user_name}

# as an option to the plug call in `web/router.ex`
plug ExAdmin.Plug.SwitchUser, current_user_name: :full_name
plug ExAdmin.Plug.SwitchUser, &MyProject.User.user_name/1
plug ExAdmin.Plug.SwitchUser, {MyProject.User, :user_name}

Summary

Functions

call(conn, opts)
do_call(current_user, conn, opts)
init(opts)