From cdc1f9b14347d777cd7956fb274ae2218c3ccbe9 Mon Sep 17 00:00:00 2001 From: Kevin McConnell Date: Tue, 2 Dec 2025 19:54:20 +0000 Subject: [PATCH] Allow typing magic links on mobile When typing a magic link, rather than pasting it, iOS seems to send `keydown.enter`, and we weren't submitting the form in that case. Changed to submit the form in either case, and use the state of the input target to help guard against double submissions. --- .../controllers/magic_link_controller.js | 14 +++++--------- app/views/sessions/magic_links/show.html.erb | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/javascript/controllers/magic_link_controller.js b/app/javascript/controllers/magic_link_controller.js index b2e487489..4d6c45ab5 100644 --- a/app/javascript/controllers/magic_link_controller.js +++ b/app/javascript/controllers/magic_link_controller.js @@ -4,16 +4,12 @@ import { onNextEventLoopTick } from "helpers/timing_helpers" export default class extends Controller { static targets = [ "input" ] - submit(event) { + submit() { onNextEventLoopTick(() => { - this.inputTarget.disabled = true - }) - } - - paste(event) { - onNextEventLoopTick(() => { - this.element.submit() - this.inputTarget.disabled = true + if (!this.inputTarget.disabled) { + this.element.submit() + this.inputTarget.disabled = true + } }) } } diff --git a/app/views/sessions/magic_links/show.html.erb b/app/views/sessions/magic_links/show.html.erb index affa97b8a..f8be106a0 100644 --- a/app/views/sessions/magic_links/show.html.erb +++ b/app/views/sessions/magic_links/show.html.erb @@ -10,7 +10,7 @@ <%= form.text_field :code, required: true, class: "input center txt-align-enter txt-large", autofocus: true, autocorrect: "off", autocapitalize: "off", spellcheck: "false", "data-1p-ignore": true, autocomplete: "one-time-code", maxlength: "6", placeholder: "••••••", value: params[:code], - data: { magic_link_target: "input", action: "keydown.enter->magic-link#submit paste->magic-link#paste" } %> + data: { magic_link_target: "input", action: "keydown.enter->magic-link#submit paste->magic-link#submit" } %> <% end %>

The code you receive will work for <%= distance_of_time_in_words(MagicLink::EXPIRATION_TIME) %>.