forked from smpallen99/ex_admin
-
Notifications
You must be signed in to change notification settings - Fork 11
Add authentication
Scott Swezey edited this page Oct 5, 2018
·
1 revision
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.