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