fix: PasswordValidation should associate errors with the field being … (#279)

This commit is contained in:
Robert Graff 2023-04-28 12:20:02 -07:00 committed by GitHub
parent 33ed10ae59
commit 2c4d8b296f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 4 deletions

View file

@ -3,7 +3,7 @@ defmodule AshAuthentication.Errors.AuthenticationFailed do
A generic, authentication failed error.
"""
use Ash.Error.Exception
def_ash_error([:strategy, caused_by: %{}], class: :forbidden)
def_ash_error([:field, :strategy, caused_by: %{}], class: :forbidden)
import AshAuthentication.Debug
@type t :: Exception.t()

View file

@ -62,6 +62,7 @@ defmodule AshAuthentication.Strategy.Password.PasswordValidation do
else
{:error,
AuthenticationFailed.exception(
field: password_arg,
strategy: strategy,
changeset: changeset
)}

View file

@ -21,7 +21,7 @@ defmodule AshAuthentication.Strategy.Password.PasswordValidationTest do
test "when provided with an incorrect password, it fails vailidation" do
user = build_user()
assert {:error, error} =
assert {:error, %AuthenticationFailed{field: :current_password}} =
user
|> Changeset.new(%{})
|> Changeset.set_argument(:current_password, password())
@ -29,8 +29,6 @@ defmodule AshAuthentication.Strategy.Password.PasswordValidationTest do
strategy_name: :password,
password_argument: :current_password
)
assert is_struct(error, AuthenticationFailed)
end
end
end