Ash_Authentication Phoenix :request_password_reset_with_password

I’m getting argument email is required error while implementing password reset link on the log in screen. How is the email supposed to be passed into the action?

The User resource includes:

  strategies do
      password :password do
        identity_field :email
        confirmation_required? false
        hashed_password_field(:hashed_password)
        register_action_name(:register_with_password)
        register_action_accept([:username])
      
        resettable do
          sender(Myapp.Accounts.User.Senders.SendPasswordResetEmail)
        end
      end
...

    read :request_password_reset_with_password do
      argument :email, Ash.Type.CiString do
        allow_nil? false
      end

      prepare AshAuthentication.Strategy.Password.RequestPasswordResetPreparation

    end

    create :password_reset_with_password do
      argument :password, :string do
        allow_nil? true
        sensitive? true
      end

      validate AshAuthentication.Strategy.Password.ResetTokenValidation

      change({AshAuthentication.Strategy.Password.HashPasswordChange, strategy_name: :password})
      change({AshAuthentication.GenerateTokenChange, strategy_name: :password})
    end

Stacktrace


[error] Something went wrong in authentication

activity: {:password, :reset_request}

reason: ** (Ash.Error.Invalid) Input Invalid

* argument email is required
  (ash 2.18.2) lib/ash/query/query.ex:560: anonymous fn/2 in Ash.Query.require_arguments/2
  (elixir 1.16.0) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
  (ash 2.18.2) lib/ash/query/query.ex:498: Ash.Query.for_read/4
  (ash_authentication 3.12.0) lib/ash_authentication/strategies/password/actions.ex:192: AshAuthentication.Strategy.Password.Actions.reset_request/3
  (ash_authentication 3.12.0) lib/ash_authentication/strategies/password/plug.ex:45: AshAuthentication.Strategy.Password.Plug.reset_request/2
  (ash_authentication 3.12.0) lib/ash_authentication/plug/dispatcher.ex:29: AshAuthentication.Plug.Dispatcher.call/2
  (phoenix 1.7.10) lib/phoenix/router.ex:432: Phoenix.Router.__call__/5
  (myapp 0.2.1) lib/myapp_web/endpoint.ex:1: MyappWeb.Endpoint.plug_builder_call/2
  (myapp 0.2.1) deps/plug/lib/plug/debugger.ex:136: MyappWeb.Endpoint."call (overridable 3)"/2
  (myapp 0.2.1) lib/myapp_web/endpoint.ex:1: MyappWeb.Endpoint.call/2
  (phoenix 1.7.10) lib/phoenix/endpoint/sync_code_reload_plug.ex:22: Phoenix.Endpoint.SyncCodeReloadPlug.do_call/4
  (plug_cowboy 2.6.1) lib/plug/cowboy/handler.ex:11: Plug.Cowboy.Handler.init/2
  (cowboy 2.10.0) c:/Users/gobey/_dev/myapp/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
  (cowboy 2.10.0) c:/Users/gobey/_dev/myapp/deps/cowboy/src/cowboy_stream_h.erl:306: :cowboy_stream_h.execute/3
  (cowboy 2.10.0) c:/Users/gobey/_dev/myapp/deps/cowboy/src/cowboy_stream_h.erl:295: :cowboy_stream_h.request_process/3
  (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
    (ash 2.18.2) lib/ash/error/error.ex:608: Ash.Error.choose_error/2
    (ash 2.18.2) lib/ash/error/error.ex:262: Ash.Error.to_error_class/2
    (ash 2.18.2) lib/ash/actions/read/read.ex:206: Ash.Actions.Read.do_run/3
    (ash 2.18.2) lib/ash/actions/read/read.ex:93: anonymous fn/3 in Ash.Actions.Read.run/3
    (ash 2.18.2) lib/ash/actions/read/read.ex:92: Ash.Actions.Read.run/3
    (myapp 0.2.1) lib/myapp/accounts/accounts.ex:1: Myapp.Accounts.read/2
    (ash_authentication 3.12.0) lib/ash_authentication/strategies/password/actions.ex:193: AshAuthentication.Strategy.Password.Actions.reset_request/3
    (ash_authentication 3.12.0) lib/ash_authentication/strategies/password/plug.ex:45: AshAuthentication.Strategy.Password.Plug.reset_request/2
    (ash_authentication 3.12.0) lib/ash_authentication/plug/dispatcher.ex:29: AshAuthentication.Plug.Dispatcher.call/2
    (phoenix 1.7.10) lib/phoenix/router.ex:432: Phoenix.Router.__call__/5
    (myapp 0.2.1) lib/myapp_web/endpoint.ex:1: MyappWeb.Endpoint.plug_builder_call/2
    (myapp 0.2.1) deps/plug/lib/plug/debugger.ex:136: MyappWeb.Endpoint."call (overridable 3)"/2
    (myapp 0.2.1) lib/myapp_web/endpoint.ex:1: MyappWeb.Endpoint.call/2
    (phoenix 1.7.10) lib/phoenix/endpoint/sync_code_reload_plug.ex:22: Phoenix.Endpoint.SyncCodeReloadPlug.do_call/4
    (plug_cowboy 2.6.1) lib/plug/cowboy/handler.ex:11: Plug.Cowboy.Handler.init/2
    (cowboy 2.10.0) c:/Users/gobey/_dev/myapp/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2

Found the answer in the documentation

      strategy = Info.strategy!(User, :password)

      ## https://hexdocs.pm/ash_authentication/AshAuthentication.Strategy.Password.html
      strategy
      |> Strategy.action(:reset_request, %{email: params["email"]})
1 Like