Authentication solution for Phoenix and Elixir using Guardian.
If available in Hex, the package can be installed as:
-
Add concierge to your list of dependencies in
mix.exs
:def deps do [{:concierge, "~> 0.0.1"}] end
-
Ensure concierge is started before your application:
def application do [applications: [:concierge]] end
-
Run
mix concierge.install
-
Add to
config/config.exs
import_config "concierge.exs"
-
Add to
web/web.ex
def controller do quote do # ... use Concierge.Controller plug Concierge.Plug.Authentication end
enddef view do quote do # ... use Concierge.Helpers end end
-
Add to
web/router.ex
concierge at: "users", pipe_through: [:browser]
-
Start server and open http://localhost:4000/users/sign_in
You will have current_user(@conn)
and user_signed_in?(@conn)
helpers in views.
Concierge provides ensure_authenticated!
controller filter. It accepts :only
and :except
options.
defmodule Example.PageController do
use Example.Web, :controller
ensure_authenticated! only: [:protected]
def index(conn, _params) do
render conn, "index.html"
end
def protected(conn, _params) do
render conn, "protected.html"
end
end
- I18n
- Confirmations
- OAuth