Magic link with registration does not work.

This works just fine if I turn registration off.
read :sign_in_with_magic_link do
description "Sign in or register a user with magic link."

argument :token, :string do
description "The token from the magic link that was sent to the user"
allow_nil? false
end

# upsert? true
# upsert_identity :unique_email
# upsert_fields [:email]

# Uses the information from the token to create or sign in the user
# change AshAuthentication.Strategy.MagicLink.SignInChange
prepare AshAuthentication.Strategy.MagicLink.SignInPreparation

metadata :token, :string do
allow_nil? false
end
end
read :sign_in_with_magic_link do
description "Sign in or register a user with magic link."

argument :token, :string do
description "The token from the magic link that was sent to the user"
allow_nil? false
end

# upsert? true
# upsert_identity :unique_email
# upsert_fields [:email]

# Uses the information from the token to create or sign in the user
# change AshAuthentication.Strategy.MagicLink.SignInChange
prepare AshAuthentication.Strategy.MagicLink.SignInPreparation

metadata :token, :string do
allow_nil? false
end
end
Now, sign in fails with invalid username/password error message if I enable registration and use the following action
create :sign_in_with_magic_link do
description "Sign in or register a user with magic link."

argument :token, :string do
description "The token from the magic link that was sent to the user"
allow_nil? false
end

upsert? true
upsert_identity :unique_email
upsert_fields [:email]

# Uses the information from the token to create or sign in the user
change AshAuthentication.Strategy.MagicLink.SignInChange

metadata :token, :string do
allow_nil? false
end
end
create :sign_in_with_magic_link do
description "Sign in or register a user with magic link."

argument :token, :string do
description "The token from the magic link that was sent to the user"
allow_nil? false
end

upsert? true
upsert_identity :unique_email
upsert_fields [:email]

# Uses the information from the token to create or sign in the user
change AshAuthentication.Strategy.MagicLink.SignInChange

metadata :token, :string do
allow_nil? false
end
end
This is a brand new ash/phoenix project. Any ideas of what may be happening?
4 Replies
ZachDaniel
ZachDaniel•2mo ago
🤔 Hmm...you should be able to IO.inspect the actual error in your auth_controller
ggarciajr
ggarciajrOP•2mo ago
@ZachDaniel I can try. the error shows up after I click the sign in button, the one that is rendered after you open the magik link
ZachDaniel
ZachDaniel•2mo ago
Right but that error message IIRC is produced in the code that is generated into your app
ggarciajr
ggarciajrOP•2mo ago
btw, does it matter that I created the user via a seed script? found the issue. I added a role attribute to user, and it is required. and it was causing the changeset to fail which caused the sign in to fail. setting the role in the magic_link action fixed the issue

Did you find this page helpful?