mirror of
https://github.com/team-alembic/ash_authentication_phoenix.git
synced 2024-09-20 05:23:55 +12:00
improvement: submit form in-line when sign_in_tokens_enabled (#274)
* improvement: submit form in-line when sign_in_tokens_enabled * chore: update ash_authentication dependency for new feature
This commit is contained in:
parent
9af7ff59ec
commit
91df24ff32
2 changed files with 32 additions and 7 deletions
|
@ -151,14 +151,39 @@ defmodule AshAuthentication.Phoenix.Components.Password.RegisterForm do
|
||||||
def handle_event("submit", params, socket) do
|
def handle_event("submit", params, socket) do
|
||||||
params = get_params(params, socket.assigns.strategy)
|
params = get_params(params, socket.assigns.strategy)
|
||||||
|
|
||||||
form = Form.validate(socket.assigns.form, params)
|
if Map.get(socket.assigns.strategy, :sign_in_tokens_enabled?) do
|
||||||
|
case Form.submit(socket.assigns.form,
|
||||||
|
params: params,
|
||||||
|
read_one?: true,
|
||||||
|
before_submit: fn changeset ->
|
||||||
|
Ash.Changeset.set_context(changeset, %{token_type: :sign_in})
|
||||||
|
end
|
||||||
|
) do
|
||||||
|
{:ok, user} ->
|
||||||
|
validate_sign_in_token_path =
|
||||||
|
route_helpers(socket).auth_path(
|
||||||
|
socket.endpoint,
|
||||||
|
{socket.assigns.subject_name, Strategy.name(socket.assigns.strategy),
|
||||||
|
:sign_in_with_token},
|
||||||
|
token: user.__metadata__.token
|
||||||
|
)
|
||||||
|
|
||||||
socket =
|
{:noreply, redirect(socket, to: validate_sign_in_token_path)}
|
||||||
socket
|
|
||||||
|> assign(:form, form)
|
|
||||||
|> assign(:trigger_action, form.valid?)
|
|
||||||
|
|
||||||
{:noreply, socket}
|
{:error, form} ->
|
||||||
|
{:noreply,
|
||||||
|
assign(socket, :form, Form.clear_value(form, socket.assigns.strategy.password_field))}
|
||||||
|
end
|
||||||
|
else
|
||||||
|
form = Form.validate(socket.assigns.form, params)
|
||||||
|
|
||||||
|
socket =
|
||||||
|
socket
|
||||||
|
|> assign(:form, form)
|
||||||
|
|> assign(:trigger_action, form.valid?)
|
||||||
|
|
||||||
|
{:noreply, socket}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_params(params, strategy) do
|
defp get_params(params, strategy) do
|
||||||
|
|
2
mix.exs
2
mix.exs
|
@ -113,7 +113,7 @@ defmodule AshAuthentication.Phoenix.MixProject do
|
||||||
# Run "mix help deps" to learn about dependencies.
|
# Run "mix help deps" to learn about dependencies.
|
||||||
defp deps do
|
defp deps do
|
||||||
[
|
[
|
||||||
{:ash_authentication, "~> 3.10"},
|
{:ash_authentication, "~> 3.11 and >= 3.11.9"},
|
||||||
{:ash_phoenix, "~> 1.1"},
|
{:ash_phoenix, "~> 1.1"},
|
||||||
{:ash, "~> 2.2"},
|
{:ash, "~> 2.2"},
|
||||||
{:jason, "~> 1.0"},
|
{:jason, "~> 1.0"},
|
||||||
|
|
Loading…
Reference in a new issue