From 533dd1273ddba301eb6a9ad6bd7237e8f1624ca7 Mon Sep 17 00:00:00 2001 From: James Harton Date: Fri, 2 Feb 2024 15:22:24 +1300 Subject: [PATCH] fix: Ensure that `sign_in_route` and `reset_route` correctly initialise session. Ensure that `AshAuthentication.Phoenix.LiveSession` is included in the `on_mount` of the generated live sessions. --- lib/ash_authentication_phoenix/router.ex | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/ash_authentication_phoenix/router.ex b/lib/ash_authentication_phoenix/router.ex index 6adeec4..68320ea 100644 --- a/lib/ash_authentication_phoenix/router.ex +++ b/lib/ash_authentication_phoenix/router.ex @@ -172,6 +172,16 @@ defmodule AshAuthentication.Phoenix.Router do scope "/", unquote(opts) do import Phoenix.LiveView.Router, only: [live: 4, live_session: 3] + on_mount = + [ + AshAuthenticationPhoenix.Router.OnLiveViewMount, + AshAuthentication.Phoenix.LiveSession | unquote(on_mount || []) + ] + |> Enum.uniq_by(fn + {mod, _} -> mod + mod -> mod + end) + live_session_opts = [ session: %{ "overrides" => unquote(overrides), @@ -180,7 +190,7 @@ defmodule AshAuthentication.Phoenix.Router do "reset_path" => unquote(reset_path), "register_path" => unquote(register_path) }, - on_mount: [AshAuthenticationPhoenix.Router.OnLiveViewMount | unquote(on_mount || [])] + on_mount: on_mount ] live_session_opts = @@ -274,9 +284,19 @@ defmodule AshAuthentication.Phoenix.Router do scope unquote(path), unquote(opts) do import Phoenix.LiveView.Router, only: [live: 4, live_session: 3] + on_mount = + [ + AshAuthenticationPhoenix.Router.OnLiveViewMount, + AshAuthentication.Phoenix.LiveSession | unquote(on_mount || []) + ] + |> Enum.uniq_by(fn + {mod, _} -> mod + mod -> mod + end) + live_session_opts = [ session: %{"overrides" => unquote(overrides), "otp_app" => unquote(otp_app)}, - on_mount: [AshAuthenticationPhoenix.Router.OnLiveViewMount | unquote(on_mount || [])] + on_mount: on_mount ] live_session_opts =