livebook/lib/livebook_web/session_identity.ex
2023-09-21 12:28:45 +02:00

18 lines
480 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_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