fix: Overrides in reset route (#250)

* Pass overrides to the banner in Reset component

* Match reset_route macro live_options with sign_in macro
This commit is contained in:
skanderm 2023-08-09 14:43:46 -07:00 committed by GitHub
parent 2cf59a7bd4
commit 2640f97823
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 11 deletions

View file

@ -64,7 +64,7 @@ defmodule AshAuthentication.Phoenix.Components.Reset do
~H"""
<div class={override_for(@overrides, :root_class)}>
<%= if override_for(@overrides, :show_banner, true) do %>
<.live_component module={Components.Banner} id="sign-in-banner" />
<.live_component module={Components.Banner} id="sign-in-banner" overrides={@overrides} />
<% end %>
<%= for strategy <- @strategies do %>

View file

@ -230,7 +230,9 @@ defmodule AshAuthentication.Phoenix.Router do
{path, opts} = Keyword.pop(opts, :path, "/password-reset")
{live_view, opts} = Keyword.pop(opts, :live_view, AshAuthentication.Phoenix.ResetLive)
{as, opts} = Keyword.pop(opts, :as, :auth)
{on_mount, opts} = Keyword.pop(opts, :on_mount, [])
{otp_app, opts} = Keyword.pop(opts, :otp_app)
{layout, opts} = Keyword.pop(opts, :layout)
{on_mount, opts} = Keyword.pop(opts, :on_mount)
{overrides, opts} =
Keyword.pop(opts, :overrides, [AshAuthentication.Phoenix.Overrides.Default])
@ -239,19 +241,26 @@ defmodule AshAuthentication.Phoenix.Router do
opts
|> Keyword.put_new(:alias, false)
live_session_opts = [
on_mount: [AshAuthenticationPhoenix.Router.OnLiveViewMount | on_mount]
]
quote do
scope unquote(path), unquote(opts) do
import Phoenix.LiveView.Router, only: [live: 4, live_session: 3]
live_session :reset, unquote(live_session_opts) do
live("/:token", unquote(live_view), :reset,
as: unquote(as),
private: %{overrides: unquote(overrides)}
)
live_session_opts = [
session: %{"overrides" => unquote(overrides), "otp_app" => unquote(otp_app)},
on_mount: [AshAuthenticationPhoenix.Router.OnLiveViewMount | unquote(on_mount || [])]
]
live_session_opts =
case unquote(layout) do
nil ->
live_session_opts
layout ->
Keyword.put(live_session_opts, :layout, layout)
end
live_session :reset, live_session_opts do
live("/:token", unquote(live_view), :reset, as: unquote(as))
end
end
end