feat(server): router pipelines + live_auth hook for authenticated dashboard
This commit is contained in:
parent
4538945b85
commit
62996d883d
2 changed files with 34 additions and 7 deletions
14
server/lib/server_web/live_auth.ex
Normal file
14
server/lib/server_web/live_auth.ex
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
defmodule ServerWeb.LiveAuth do
|
||||
@moduledoc "on_mount hook for LiveView sessions requiring authentication."
|
||||
|
||||
import Phoenix.LiveView
|
||||
import Phoenix.Component, only: [assign: 3]
|
||||
|
||||
def on_mount(:require_authenticated, _params, session, socket) do
|
||||
if session["authenticated"] do
|
||||
{:cont, assign(socket, :authenticated, true)}
|
||||
else
|
||||
{:halt, redirect(socket, to: "/login")}
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue