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

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews