Complete authentication flow with dummy password

This commit is contained in:
Claudio Ortolina
2024-10-20 19:25:31 +01:00
parent b5bceb92e0
commit 4fcfc6c921
4 changed files with 46 additions and 10 deletions
@@ -0,0 +1,21 @@
defmodule MusicLibraryWeb.Plug.RequireLogin do
@behaviour Plug
import Plug.Conn
import Phoenix.Controller, only: [put_flash: 3, redirect: 2]
@impl true
def init(opts), do: opts
@impl true
def call(conn, _opts) do
if get_session(conn, :logged_in) do
conn
else
conn
|> put_flash(:error, "You must be logged in to access this page")
|> redirect(to: "/login")
|> halt()
end
end
end