Ash FrameworkAF
Ash Frameworkβ€’3y agoβ€’
37 replies
tellesleandro

Exception in transformer AshAuthentication.Strategy.Custom.Transformer

Hi there.

I got an exception in transformer AshAuthentication.Strategy.Custom.Transformer when following the Authentication guide . Instead of User I set the resource name to Usuario.

== Compilation error in file lib/garagem/seguranca/resources/usuario.ex ==
** (RuntimeError) Exception in transformer AshAuthentication.Strategy.Custom.Transformer on Garagem.Seguranca.Usuario: 

expected a map, got: nil
    (elixir 1.15.4) lib/map.ex:486: Map.take/2
    (ash_authentication 3.11.14) lib/ash_authentication/strategies/password/transformer.ex:78: anonymous fn/2 in AshAuthentication.Strategy.Password.Transformer.transform/2
...

mix.exs

...
{:ash, "~> 2.14"},
{:ash_postgres, "~> 1.3"},
{:ash_phoenix, "~> 1.2"},
{:ash_authentication, "~> 3.11"},
{:ash_authentication_phoenix, "~> 1.8"}
...


Resource file

defmodule Garagem.Seguranca.Usuario do
  use Ash.Resource,
    data_layer: AshPostgres.DataLayer,
    extensions: [AshAuthentication]

  attributes do
    uuid_primary_key :id
    attribute :email, :ci_string, allow_nil?: false
    attribute :hashed_password, :string, allow_nil?: false, sensitive?: true
  end

  authentication do
    api Garagem.Seguranca

    strategies do
      password :password do
        identity_field :email
        sign_in_tokens_enabled? true
      end
    end

    tokens do
      enabled? true
      token_resource Garagem.Seguranca.Token

      signing_secret Garagem.Seguranca.Secrets
    end
  end

  postgres do
    table "usuarios"
    repo Garagem.Repo
  end

  identities do
    identity :unique_email, [:email]
  end
end


The resettable property of the struct strategy is nil at ash_authentication/strategies/password/transformer.ex:77.

I tried to set the property to a function, as shown in the docs (https://hexdocs.pm/ash_authentication/AshAuthentication.Sender.html), but I still get the error.

I hope someone can help me.

Thanks
Was this page helpful?