Skip to content
Steve Pallen edited this page May 11, 2016 · 4 revisions

If you would like to add the currently logged in user as well as a logout link, you can implement the ExAdmin.Authentication protocol. For example, add the following lib/myapp/authentication.ex file in your project:

defimpl ExAdmin.Authentication, for: Plug.Conn do
  alias MyApp.Router.Helpers
  alias MyApp.Authentication, as: Auth

  def use_authentication?(_), do: true
  def current_user(conn), do: Auth.current_user(conn)
  def current_user_name(conn), do: Auth.current_user(conn).name
  def session_path(conn, action), do: Helpers.session_path(conn, action)
end

defmodule MyApp.Authentication do
  def current_user(conn) do
    YouFavAuthLib.some_get_authenticated_user(conn)
  end
end

For a detailed example of ExAdmin for a system that uses Authentication, take a look at ExAdmin Contacts Demo.