livebook/lib/livebook_web/live/hooks/auth_hook.ex

17 lines
413 B
Elixir
Raw Normal View History

defmodule LivebookWeb.AuthHook do
import Phoenix.LiveView
2023-02-23 02:34:54 +08:00
use LivebookWeb, :verified_routes
def on_mount(:default, _params, session, socket) do
uri = get_connect_info(socket, :uri)
auth_mode = Livebook.Config.auth_mode()
if LivebookWeb.AuthPlug.authenticated?(session || %{}, uri.port, auth_mode) do
{:cont, socket}
else
2023-02-23 02:34:54 +08:00
{:halt, redirect(socket, to: ~p"/")}
end
end
end