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:
Zach Daniel 2023-09-17 20:42:14 -04:00 committed by GitHub
parent 9af7ff59ec
commit 91df24ff32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 7 deletions

View file

@ -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

View file

@ -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"},