Skip to content

sign in via QR code 📸

Yaro Shm edited this page Mar 10, 2024 · 1 revision

You can use gem rqrcode to generate a QR code to login.

Update app/views/passwordless/mailer/sign_in.html.erb:

<% qrcode = RQRCode::QRCode.new(@magic_link) %>

<% svg = qrcode.as_svg(
  offset: 0,
  color: '000',
  shape_rendering: 'crispEdges',
  module_size: 11,
  viewbox: true, # to control width within div. if "false", width is controlled by module_size
  standalone: true) %>

<div style="width: 200px;">
  <%= raw svg %>
</div>

result:

Screenshot 2024-03-10 at 16 30 48

It is tricker to display the QR code in plain-text email. So far this is the closest I got by updating app/views/passwordless/mailer/sign_in.text.erb:

<% qrcode = RQRCode::QRCode.new("http:https://github.com/") %>
<%= qrcode.to_s.gsub('x', "\u2588") %>
Screenshot 2024-03-10 at 18 57 41

🚨 My phone did not manage to read this plain-text QR code. Better solutions would be appreciated