diff --git a/lib/ash_authentication_phoenix/ash_phoenix_errors.ex b/lib/ash_authentication_phoenix/ash_phoenix_errors.ex index 6eb3d2e..25efdf0 100644 --- a/lib/ash_authentication_phoenix/ash_phoenix_errors.ex +++ b/lib/ash_authentication_phoenix/ash_phoenix_errors.ex @@ -1,7 +1,12 @@ defimpl AshPhoenix.FormData.Error, for: AshAuthentication.Errors.AuthenticationFailed do import PhoenixHTMLHelpers.Form, only: [humanize: 1] - def to_form_error(error) when is_struct(error.strategy, AshAuthentication.Strategy.Password) do + def to_form_error(error) when is_struct(error.strategy, AshAuthentication.Strategy.Password), + do: to_auth_failed_error(error) + + def to_form_error(_), do: [] + + defp to_auth_failed_error(error) when error.strategy.password_field == error.field do [ {error.strategy.password_field, "#{humanize(error.strategy.identity_field)} or #{downcase_humanize(error.strategy.password_field)} was incorrect", @@ -9,7 +14,11 @@ defimpl AshPhoenix.FormData.Error, for: AshAuthentication.Errors.AuthenticationF ] end - def to_form_error(_), do: [] + defp to_auth_failed_error(error) do + [ + {error.field, "#{humanize(error.field)} was incorrect", []} + ] + end defp downcase_humanize(value) do value