Ash FrameworkAF
Ash Framework5mo ago
9 replies
Arvind S.

Any pointers on testing authenticated LV's with AshAuthentication Magic Link?

I'm attempting to reproduce a similar workflow to the email/password instructions in the docs but am running into issues around confirmation add ons when combined with magic link authentication.

My current setup looks like this, but is erroring with a Fails with AshAuthentication.Errors.CannotConfirmUnconfirmedUser:

def register_and_log_in_user(%{conn: conn} = context) do
 user = Ash.Seed.seed!(MyApp.Accounts.User, %{email: "test@gmail.com"})

 strategy = AshAuthentication.Info.strategy!(MyApp.Accounts.User, :magic_link)

 AshAuthentication.Strategy.action(strategy, :request, %{email: user.email})

 {:ok, token} = AshAuthentication.Strategy.MagicLink.request_token_for(strategy, user)
 {:ok, authenticated } = AshAuthentication.Strategy.action(strategy, :sign_in, %{token: token})

 new_conn =
    conn
    |> Phoenix.ConnTest.init_test_session(%{})
    |> AshAuthentication.Plug.Helpers.store_in_session(authenticated)

    %{context | conn: new_conn}
  end


Any guidance would be much appreciated!
GitHub
The Ash Authentication framework. Contribute to team-alembic/ash_authentication development by creating an account on GitHub.
ash_authentication/documentation/topics/testing.md at main · team-...
Was this page helpful?