mikesax

mikesax

I am implementing Ash MagicLink Authentication (registration enabled, require interaction, and single use token) with my custom link confirmation page. If the token is valid it shows a welcome message, otherwise, it redirects to a the sign-in page:

  @impl true
  def mount(%{"token" => token}, _session, socket) do
    if token_valid?(token) do
      {:ok, assign(socket, token: token)}
    else
      {:ok, push_navigate(socket, to: ~p"/start/again")}
    end
  end

  defp token_valid?(token) do
    changeset =
      Welcomepad.Accounts.User
      |> Ash.Changeset.for_create(:sign_in_with_magic_link, %{token: token})

    changeset.valid?
  end

This works great but if the token is valid, I would like to show some different information, depending on the user, in the intro that asks them to push the sign-in button (which then does the POST to do a proper sign-in). For example, if it’s a brand new user, I’d like to show an on-boarding message.

I can’t find an easy way to get the user from a valid magic link token (without actually signing in that user). I guess I could turn off single-use tokens (and destroy the token manually after a sign-in) but that seems like a bit of a hack. Is there a more elegant solution?

Showing Posts 1 to 5

ken-kost

ken-kost

But couldn’t you show onboarding screens after login to first time user? i.e. attribute first_login?, :boolean, default: true. and if true you show it and switch it off. :thinking:

mikesax

mikesax OP

I want to avoid having a “useless” screen. Technically it’s needed since it requires interaction to trigger the POST, but if it’s just a “Sign In” button, from the user’s perspective it feels like a wasted click. During onboarding, every click matters, so I’d rather show something more engaging. If the first_login? attribute you suggest belongs to the User resource, I’m back to square one: I still need to know which user a valid token belongs to.

zachdaniel

zachdaniel

Creator of Ash

Assuming you’re hand rolling the page, my suggestion would be to add fields to the sign in with magic link action and then use an after action hook. So there would be new fields alongside the sign in button.

mikesax

mikesax OP

Yes, I’m hand rolling the page. But wouldn’t those new fields only be available after the sign in? I want to show different info after the user taps the magic link but before they press the button that does a POST to the form.

For now, I have solved it by sending two different emails, with to slightly different links, depending on whether the email is a brand new or belongs to an already onboarded user. In the router, the different URLs point to the same page but with a different action:

live "/signin/t/:token", AuthLive.Confirm, :signin
live "/signup/t/:token", AuthLive.Confirm, :singup

This way, in the HTML I can simply check @live_action and either show a fancy onboarding welcome screen, or a simple “Open MyApp” button.

Thanks for your help!

zachdaniel

zachdaniel

Creator of Ash

The sign in like create/sign in happens when you press that button. The user is created when they click “sign in”, so it sounds like what you did is pretty much exactly what I was suggesting I think.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews