From ef856bf14ef08495bf647815bd65b2069378306c Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Tue, 16 Jul 2024 15:31:48 -0400 Subject: [PATCH] fix: set tenant in sign_in and reset_route (#478) --- lib/ash_authentication_phoenix/router.ex | 27 +++++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/ash_authentication_phoenix/router.ex b/lib/ash_authentication_phoenix/router.ex index 68320ea..1c1641a 100644 --- a/lib/ash_authentication_phoenix/router.ex +++ b/lib/ash_authentication_phoenix/router.ex @@ -183,13 +183,17 @@ defmodule AshAuthentication.Phoenix.Router do end) live_session_opts = [ - session: %{ - "overrides" => unquote(overrides), - "otp_app" => unquote(otp_app), - "path" => unquote(path), - "reset_path" => unquote(reset_path), - "register_path" => unquote(register_path) - }, + session: + {AshAuthentication.Phoenix.Router, :generate_session, + [ + %{ + "overrides" => unquote(overrides), + "otp_app" => unquote(otp_app), + "path" => unquote(path), + "reset_path" => unquote(reset_path), + "register_path" => unquote(register_path) + } + ]}, on_mount: on_mount ] @@ -295,7 +299,9 @@ defmodule AshAuthentication.Phoenix.Router do end) live_session_opts = [ - session: %{"overrides" => unquote(overrides), "otp_app" => unquote(otp_app)}, + session: + {AshAuthentication.Phoenix.Router, :generate_session, + [%{"overrides" => unquote(overrides), "otp_app" => unquote(otp_app)}]}, on_mount: on_mount ] @@ -314,4 +320,9 @@ defmodule AshAuthentication.Phoenix.Router do end end end + + @doc false + def generate_session(conn, session) do + Map.put(session, "tenant", Ash.PlugHelpers.get_tenant(conn)) + end end