Ash FrameworkAF
Ash Frameworkโ€ข7mo agoโ€ข
4 replies
aidalgol

Testing with AshAuthentication after upgrade

After upgrading ash_authentication_phoenix and ash_authentication to 2.10.0 and 2.9.2, this test helper function raises an error.
  @doc """
  Logs in a user with `AshAuthentication` as the current user.
  """
  def log_in_user_as_subject(conn, user) do
    conn
    |> Phoenix.ConnTest.init_test_session(%{})
    |> AshAuthentication.Phoenix.Plug.store_in_session(user)
    |> Plug.Conn.assign(:current_user, user)
  end

     ** (KeyError) key :token not found in: %{}
     code: conn = log_in_user_as_subject(conn, user)
     stacktrace:
       (ash_authentication 4.9.2) lib/ash_authentication/plug/helpers.ex:18: AshAuthentication.Plug.Helpers.store_in_session/2

Looks like it's because I'm creating users for test using Ash.Seed.seed!, so nothing is populating token.
User
|> Ash.Seed.seed!(%{email: "bob@example.net", hashed_password: "..."})

What would be a sensible fix here?
Solution
๐Ÿค” You could generate a token and put it into __metadata__
Was this page helpful?