How to login with a generated Magic Link in Phoenix (ash_authentication ash_phoenix_authentication)

I'm trying to implement the new Magic Link strategy in ash_authentication. I can succesfully send an email with a magic link token, but how do I use that token to then login the user? For example with password reset, the token goes in the url, and that works, I'd imagine you have to do something similar with a magic link, but that route doesn't seem to be available. This is what mix phx.routes returns, where there's no room to put a token.
auth_path * /auth/user/magic_link/request ExampleWeb.AuthController {:user, :magic_link, :request}
auth_path * /auth/user/magic_link ExampleWeb.AuthController {:user, :magic_link, :sign_in}
auth_path * /auth/user/magic_link/request ExampleWeb.AuthController {:user, :magic_link, :request}
auth_path * /auth/user/magic_link ExampleWeb.AuthController {:user, :magic_link, :sign_in}
So my question is what URL should the email return, and how do I login with that URL. I imagine I have to make a controller for it but I couldn't find anything in the docs for it.
4 Replies
ZachDaniel
ZachDaniel2y ago
@jart
Wout
WoutOP2y ago
Found the solution, should have read a bit better. There's definitely value in guides like this for magic links for dummies like me: https://ash-hq.org/docs/guides/ash_authentication_phoenix/latest/tutorials/getting-started-with-ash-authentication-phoenix Solution: Specify the url like so: /auth/user/magic_link?token=<your_magic_link_token> It's specified in here: https://ash-hq.org/docs/module/ash_authentication/latest/ashauthentication-strategy-magiclink#examples- ("/user/magic_link", %{"token" => token})
ZachDaniel
ZachDaniel2y ago
You could write one if you have some time! You’d PR a markdown file to the documentation/tutorials folder in ash_authentication 🙂 Even if it’s very barebones Every little bit helps

Did you find this page helpful?