Skip to content

Commit

Permalink
fix: Ensure that sign_in_route and reset_route correctly initiali…
Browse files Browse the repository at this point in the history
…se session.

Ensure that `AshAuthentication.Phoenix.LiveSession` is included in the `on_mount` of the generated live sessions.
  • Loading branch information
jimsynz committed Feb 2, 2024
1 parent d305d3e commit 533dd12
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/ash_authentication_phoenix/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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 =
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 533dd12

Please sign in to comment.