mirror of
https://github.com/team-alembic/ash_authentication_phoenix.git
synced 2024-09-19 21:13:52 +12:00
fix: honour the error field in AuthenticationFailed errors in forms. (#368)
When the field being validated is not the strategy's password field then don't show the normal validation message.
This commit is contained in:
parent
2c3a12afa7
commit
82c4788962
1 changed files with 11 additions and 2 deletions
|
@ -1,7 +1,12 @@
|
||||||
defimpl AshPhoenix.FormData.Error, for: AshAuthentication.Errors.AuthenticationFailed do
|
defimpl AshPhoenix.FormData.Error, for: AshAuthentication.Errors.AuthenticationFailed do
|
||||||
import PhoenixHTMLHelpers.Form, only: [humanize: 1]
|
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,
|
{error.strategy.password_field,
|
||||||
"#{humanize(error.strategy.identity_field)} or #{downcase_humanize(error.strategy.password_field)} was incorrect",
|
"#{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
|
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
|
defp downcase_humanize(value) do
|
||||||
value
|
value
|
||||||
|
|
Loading…
Reference in a new issue