Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/ash_authentication_phoenix/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,27 @@ defmodule AshAuthentication.Phoenix.Router do
value -> Phoenix.Router.scoped_path(__MODULE__, value)
end

register_route_path =
case unquote(register_path) do
nil -> nil
{:unscoped, value} -> value
value -> value
end

reset_path =
case unquote(reset_path) do
nil -> nil
{:unscoped, value} -> value
value -> Phoenix.Router.scoped_path(__MODULE__, value)
end

reset_route_path =
case unquote(reset_path) do
nil -> nil
{:unscoped, value} -> value
value -> value
end

auth_routes_prefix =
case unquote(auth_routes_prefix) do
nil -> nil
Expand Down Expand Up @@ -396,11 +410,13 @@ defmodule AshAuthentication.Phoenix.Router do
live(unquote(path), unquote(live_view), :sign_in, as: unquote(as))

if reset_path do
live(reset_path, unquote(live_view), :reset, as: :"#{unquote(as)}_reset")
live(reset_route_path, unquote(live_view), :reset, as: :"#{unquote(as)}_reset")
end

if register_path do
live(register_path, unquote(live_view), :register, as: :"#{unquote(as)}_register")
live(register_route_path, unquote(live_view), :register,
as: :"#{unquote(as)}_register"
)
end
end
end
Expand Down
13 changes: 9 additions & 4 deletions test/router_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ defmodule AshAuthentication.Phoenix.RouterTest do
end

test "sign_in_routes respects the inherited router scope" do
route =
AshAuthentication.Phoenix.Test.Router
|> Phoenix.Router.routes()
|> Enum.find(&(&1.path == "/nested/sign-in"))
routes = Phoenix.Router.routes(AshAuthentication.Phoenix.Test.Router)

route = Enum.find(routes, &(&1.path == "/nested/sign-in"))

{_, _, _, %{extra: %{session: session}}} = route.metadata.phoenix_live_view

Expand All @@ -52,6 +51,12 @@ defmodule AshAuthentication.Phoenix.RouterTest do
"resources" => nil
}
]}

assert Enum.find(routes, &(&1.path == "/nested/reset")),
"reset route should be at /nested/reset, not /nested/nested/reset"

assert Enum.find(routes, &(&1.path == "/nested/register")),
"register route should be at /nested/register, not /nested/nested/register"
end

test "sign_in_routes respects unscoped" do
Expand Down
Loading