livebook/lib/livebook_web/session_identity.ex
2023-11-15 17:33:43 +01:00

18 lines
485 B
Elixir

defmodule LivebookWeb.SessionIdentity do
# This module implements the ZTA contract specific to Livebook cookies
import Plug.Conn
def authenticate(_, conn, _) do
if id = get_session(conn, :current_user_id) do
{conn, %{id: id}}
else
user_id = Livebook.Utils.random_long_id()
{put_session(conn, :current_user_id, user_id), %{id: user_id}}
end
end
def child_spec(_opts) do
%{id: __MODULE__, start: {Function, :identity, [:ignore]}}
end
end