mirror of
https://github.com/team-alembic/ash_authentication_phoenix.git
synced 2024-09-20 05:23:55 +12:00
fix: apply auth_routes_prefix
logic to reset_route
as well
This commit is contained in:
parent
0ddb468cc9
commit
870964155c
6 changed files with 42 additions and 8 deletions
|
@ -31,7 +31,7 @@ defmodule DevWeb.Router do
|
||||||
pipe_through :browser
|
pipe_through :browser
|
||||||
|
|
||||||
sign_out_route(AuthController, "/sign-out")
|
sign_out_route(AuthController, "/sign-out")
|
||||||
reset_route()
|
reset_route(auth_routes_prefix: "/auth")
|
||||||
|
|
||||||
sign_in_route(
|
sign_in_route(
|
||||||
path: "/sign-in",
|
path: "/sign-in",
|
||||||
|
|
|
@ -377,7 +377,7 @@ defmodule ExampleWeb.Router do
|
||||||
# Leave out `register_path` and `reset_path` if you don't want to support
|
# Leave out `register_path` and `reset_path` if you don't want to support
|
||||||
# user registration and/or password resets respectively.
|
# user registration and/or password resets respectively.
|
||||||
sign_in_route(register_path: "/register", reset_path: "/reset", auth_routes_prefix: "/auth")
|
sign_in_route(register_path: "/register", reset_path: "/reset", auth_routes_prefix: "/auth")
|
||||||
reset_route []
|
reset_route [auth_routes_prefix: "/auth"]
|
||||||
|
|
||||||
# <-- add these lines
|
# <-- add these lines
|
||||||
end
|
end
|
||||||
|
@ -431,7 +431,7 @@ Liveviews provided by AshAuthentication.Phoenix will use the same root layout co
|
||||||
If you would like to use your own layout file instead, you can specify this as an option to the route helpers, eg.
|
If you would like to use your own layout file instead, you can specify this as an option to the route helpers, eg.
|
||||||
|
|
||||||
```elixir
|
```elixir
|
||||||
reset_route(layout: {MyAppWeb, :live})
|
reset_route(layout: {MyAppWeb, :live}, auth_routes_prefix: "/auth")
|
||||||
```
|
```
|
||||||
|
|
||||||
## AuthController
|
## AuthController
|
||||||
|
|
|
@ -89,7 +89,15 @@ defmodule AshAuthentication.Phoenix.Components.Password.ResetForm do
|
||||||
phx-submit="submit"
|
phx-submit="submit"
|
||||||
phx-change="change"
|
phx-change="change"
|
||||||
phx-target={@myself}
|
phx-target={@myself}
|
||||||
action={auth_path(@socket, @subject_name, @auth_routes_prefix, @strategy, :reset_request)}
|
action={
|
||||||
|
auth_path(
|
||||||
|
@socket,
|
||||||
|
@subject_name,
|
||||||
|
@auth_routes_prefix,
|
||||||
|
@strategy,
|
||||||
|
:reset_request
|
||||||
|
)
|
||||||
|
}
|
||||||
method="POST"
|
method="POST"
|
||||||
class={override_for(@overrides, :form_class)}
|
class={override_for(@overrides, :form_class)}
|
||||||
>
|
>
|
||||||
|
|
|
@ -105,7 +105,15 @@ defmodule AshAuthentication.Phoenix.Components.Reset.Form do
|
||||||
phx-submit="submit"
|
phx-submit="submit"
|
||||||
phx-trigger-action={@trigger_action}
|
phx-trigger-action={@trigger_action}
|
||||||
phx-target={@myself}
|
phx-target={@myself}
|
||||||
action={auth_path(@socket, @subject_name, @auth_routes_prefix, @strategy, :reset)}
|
action={
|
||||||
|
auth_path(
|
||||||
|
@socket,
|
||||||
|
@subject_name,
|
||||||
|
@auth_routes_prefix,
|
||||||
|
@strategy,
|
||||||
|
:reset
|
||||||
|
)
|
||||||
|
}
|
||||||
method="POST"
|
method="POST"
|
||||||
class={override_for(@overrides, :form_class)}
|
class={override_for(@overrides, :form_class)}
|
||||||
>
|
>
|
||||||
|
|
|
@ -33,6 +33,7 @@ defmodule AshAuthentication.Phoenix.ResetLive do
|
||||||
|> assign_new(:otp_app, fn -> nil end)
|
|> assign_new(:otp_app, fn -> nil end)
|
||||||
|> assign(:current_tenant, session["tenant"])
|
|> assign(:current_tenant, session["tenant"])
|
||||||
|> assign(:context, session["context"] || %{})
|
|> assign(:context, session["context"] || %{})
|
||||||
|
|> assign(:auth_routes_prefix, session["auth_routes_prefix"])
|
||||||
|
|
||||||
{:ok, socket}
|
{:ok, socket}
|
||||||
end
|
end
|
||||||
|
@ -55,6 +56,7 @@ defmodule AshAuthentication.Phoenix.ResetLive do
|
||||||
otp_app={@otp_app}
|
otp_app={@otp_app}
|
||||||
id={override_for(@overrides, :reset_id, "reset")}
|
id={override_for(@overrides, :reset_id, "reset")}
|
||||||
token={@token}
|
token={@token}
|
||||||
|
auth_routes_prefix={@auth_routes_prefix}
|
||||||
overrides={@overrides}
|
overrides={@overrides}
|
||||||
current_tenant={@current_tenant}
|
current_tenant={@current_tenant}
|
||||||
context={@context}
|
context={@context}
|
||||||
|
|
|
@ -26,10 +26,10 @@ defmodule AshAuthentication.Phoenix.Router do
|
||||||
|
|
||||||
scope "/", MyAppWeb do
|
scope "/", MyAppWeb do
|
||||||
pipe_through :browser
|
pipe_through :browser
|
||||||
sign_in_route
|
sign_in_route auth_routes_prefix: "/auth"
|
||||||
sign_out_route AuthController
|
sign_out_route AuthController
|
||||||
auth_routes_for MyApp.Accounts.User, to: AuthController
|
auth_routes_for MyApp.Accounts.User, to: AuthController
|
||||||
reset_route
|
reset_route auth_routes_prefix: "/auth"
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
|
@ -136,6 +136,8 @@ defmodule AshAuthentication.Phoenix.Router do
|
||||||
If you are using any of the components provided by `AshAuthenticationPhoenix`, you will need to supply
|
If you are using any of the components provided by `AshAuthenticationPhoenix`, you will need to supply
|
||||||
them with the `auth_routes_prefix` assign, set to the `path` you provide here (set to `/auth` by default).
|
them with the `auth_routes_prefix` assign, set to the `path` you provide here (set to `/auth` by default).
|
||||||
|
|
||||||
|
You also will need to set `auth_routes_prefix` on the `reset_route`, i.e `reset_route(auth_routes_prefix: "/auth")`
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
* `path` - the path to mount auth routes at. Defaults to `/auth`. If changed, you will also want
|
* `path` - the path to mount auth routes at. Defaults to `/auth`. If changed, you will also want
|
||||||
|
@ -360,6 +362,7 @@ defmodule AshAuthentication.Phoenix.Router do
|
||||||
{otp_app, opts} = Keyword.pop(opts, :otp_app)
|
{otp_app, opts} = Keyword.pop(opts, :otp_app)
|
||||||
{layout, opts} = Keyword.pop(opts, :layout)
|
{layout, opts} = Keyword.pop(opts, :layout)
|
||||||
{on_mount, opts} = Keyword.pop(opts, :on_mount)
|
{on_mount, opts} = Keyword.pop(opts, :on_mount)
|
||||||
|
{auth_routes_prefix, opts} = Keyword.pop(opts, :auth_routes_prefix)
|
||||||
|
|
||||||
{overrides, opts} =
|
{overrides, opts} =
|
||||||
Keyword.pop(opts, :overrides, [AshAuthentication.Phoenix.Overrides.Default])
|
Keyword.pop(opts, :overrides, [AshAuthentication.Phoenix.Overrides.Default])
|
||||||
|
@ -369,6 +372,13 @@ defmodule AshAuthentication.Phoenix.Router do
|
||||||
|> Keyword.put_new(:alias, false)
|
|> Keyword.put_new(:alias, false)
|
||||||
|
|
||||||
quote do
|
quote do
|
||||||
|
auth_routes_prefix =
|
||||||
|
case unquote(auth_routes_prefix) do
|
||||||
|
nil -> nil
|
||||||
|
{:unscoped, value} -> value
|
||||||
|
value -> Phoenix.Router.scoped_path(__MODULE__, value)
|
||||||
|
end
|
||||||
|
|
||||||
scope unquote(path), unquote(opts) do
|
scope unquote(path), unquote(opts) do
|
||||||
import Phoenix.LiveView.Router, only: [live: 4, live_session: 3]
|
import Phoenix.LiveView.Router, only: [live: 4, live_session: 3]
|
||||||
|
|
||||||
|
@ -385,7 +395,13 @@ defmodule AshAuthentication.Phoenix.Router do
|
||||||
live_session_opts = [
|
live_session_opts = [
|
||||||
session:
|
session:
|
||||||
{AshAuthentication.Phoenix.Router, :generate_session,
|
{AshAuthentication.Phoenix.Router, :generate_session,
|
||||||
[%{"overrides" => unquote(overrides), "otp_app" => unquote(otp_app)}]},
|
[
|
||||||
|
%{
|
||||||
|
"auth_routes_prefix" => auth_routes_prefix,
|
||||||
|
"overrides" => unquote(overrides),
|
||||||
|
"otp_app" => unquote(otp_app)
|
||||||
|
}
|
||||||
|
]},
|
||||||
on_mount: on_mount
|
on_mount: on_mount
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue