Magic Link Emails: How Passwordless Login Works

Magic Link Emails: How Passwordless Login Works

A magic link email authenticates a user without a password: the app emails a single-use, time-limited link, and clicking it logs the user in directly. There’s no code to read and retype, no password to recall, just one click that lands the user in an authenticated session. The whole mechanism depends on one thing: the token embedded in that link. It has to be generated with a cryptographically secure random source, stored as a hash rather than in plain text, scoped to expire quickly, and invalidated the instant it’s redeemed. Get any of those wrong and the link becomes a security hole instead of a login.

This post covers that token contract, the risks specific to email-based auth, and how magic links stack up against email OTP and traditional passwords.

How the Magic Link Flow Works

The flow replaces the password field with an email address field and moves the actual authentication step into a background token exchange:

  1. The user enters their email address. There is no password field.
  2. The server generates a token with CSPRNG(32 bytes), encoded as url-safe base64.
  3. The server stores sha256(token), the user ID, an expiry time and used = false. The raw token is never stored.
  4. The server emails a link such as https://app.example.com/auth/verify?token={raw_token}.
  5. The user opens the email and clicks the link.
  6. The server looks up sha256(incoming_token) and checks the expiry and the used flag.
  7. If the token is valid, the server creates a session, sets used = true and redirects into the app.
  8. If the token is invalid or expired, the server shows a “request a new link” prompt.

The token is the entire authentication factor. There’s no password to fall back on, which is why steps 2 and 3, generation and storage, carry more weight here than in a standard login form.

The Token Contract: What Makes a Magic Link Secure

The security properties are the same ones OWASP defines for any single-use authentication link. The OWASP Forgot Password Cheat Sheet requires tokens to be “generated using a cryptographically secure random number generator,” “long enough to protect against brute-force attacks,” and “invalidated after they have been used.” OWASP does not state a bit length. As a rule of thumb, 128 bits (16 random bytes) is a common floor, and the flow above uses 32 bytes (256 bits). For a magic link, invalidation means the first successful click, since there’s no separate password-change step to wait for the way there is in a reset flow.

The token is a random value that the server looks up by its hash, not a signed token such as a JWT. Signed tokens can be verified without a database read, but making them single-use still requires server-side state, so the stored-hash design is simpler for this job.

Two properties matter more here than they do for a password reset link:

  • Expiry window. The link is the entire login, not a detour to a form, so it can and should expire fast. Supabase’s documentation states its default magic links “expire after 1 hour.” The NIST SP 800-63B rule for out-of-band authentication is stricter: “In all cases, the authentication SHALL be considered invalid unless completed within 10 minutes” (Section 3.1.3.2). Ten minutes or less is a defensible target. Going longer, to 15 or 30 minutes, trades some security for tolerance of slow email delivery.
  • Storage. Store a hash of the token (SHA-256), never the raw value. A database read doesn’t hand an attacker working login links.

NIST also sets a ceiling on what email login can claim. SP 800-63B states that “Email SHALL NOT be used for out-of-band authentication” (Section 3.1.3.1), because the channel can be reached with only a password, intercepted in transit, or rerouted. A magic link is a convenience login, not an assurance-level authenticator, so pair it with a stronger method before sensitive actions.

Security Risks Specific to Magic Links

Link interception. A magic link is a bearer credential: whoever holds it is logged in, no additional check required. That makes forwarded emails, shared inboxes (support teams, family accounts), and browser history on a shared computer genuine attack surfaces in a way a password alone is not.

Email security scanners that burn the token before the user clicks it. Corporate, university, and hospital email systems commonly run inbound links through security scanners that fetch the URL to inspect it before the message reaches the inbox. That fetch consumes a single-use token. One developer reporting the problem to Supabase described the pattern in a community discussion: “Magic links and password reset links are frequently consumed by automated email scanners in enterprise, university, and hospital environments,” adding “but the root cause for me is usually mail infrastructure prefetching the URL.” That is one developer’s experience, not a Supabase statement. The user then clicks a link that’s already dead and sees an opaque error.

Mitigations for scanner prefetch. The reliable fix is a landing page that does not redeem the token on load. The page shows a “Sign in” button, and only the button press sends the token in a POST request that redeems it. A URL fragment (#token=...) helps a little, because fragments aren’t sent to the server on a plain GET. But scanners that run a headless browser can execute page JavaScript and read the fragment, so the fragment alone does not protect the token. The click-to-redeem step does.

Same-browser, same-device requirements. Some implementations tie the request to the browser session that initiated it, which breaks a common real pattern: a user requests the link on desktop Chrome, but their phone’s mail app opens it in a different default browser. Auth0 flags this directly in its own passwordless documentation, noting that “both the initial request and its response must take place in the same browser or the transaction will fail,” and that this trips up iOS users specifically because “the user might make the initial request using the Chrome browser, but when the user opens the Magic Link in their email, iOS automatically opens it in Safari.” If your implementation has this constraint, budget for a visible “resend the link” path as a normal part of the flow, not an edge case.

Email account takeover. If an attacker controls the recipient’s inbox, they control every magic link sent to it, with no separate password to reset as a checkpoint. This is the core tradeoff of any email-based authentication method, and it has no mitigation at the application layer: there’s no “old password” to require, because there isn’t one.

Magic Link vs. Email OTP vs. Password

Magic LinkEmail OTPPassword
User actionClick one linkRead a code, type it inRecall and type a password
Cross-device frictionHigh unless the link opens where the session startedLow, the code can be typed on any deviceNone
Phishing via live relayHarder, requires intercepting a URL clickEasier, a fake page can ask for the code and relay it in real timeClassic credential phishing
Exposed by email interceptionYes, the link is a bearer credentialYes, for its short validity windowNo email dependency
Underlying mechanismRandom single-use token, stored hashedSame kind of token, delivered as a short codeSeparate: a stored, hashed credential

Supabase’s own architecture makes the overlap explicit: “email OTPs share an implementation with magic links,” per its passwordless email documentation. The flow is the same underneath (a single-use secret, emailed, redeemed once), delivered as a clickable URL in one case and a typed code in the other. That doesn’t make them equivalent in security. A 6-digit code has only about 1 million possible values, so it needs strict attempt limits and short expiry, while a 256-bit link token can’t be guessed. And as the table shows, a code is easier to relay through a phishing page in real time. For most products the UX tradeoff still decides: magic links remove typing but confine the user to whatever context they started the request in, while OTP codes work on any device the user has in front of them, at the cost of retyping a code.

Why Delivery Speed Decides Whether Magic Links Work at All

A magic link with a 10-minute expiry is worthless if the email takes 8 minutes to arrive. Unlike marketing email, where a delay of an hour goes unnoticed, an auth email that lands late looks broken and pushes the user straight to “resend” or gives up. Postmark states the stakes plainly on its own deliverability page: “if it doesn’t hit their inbox instantly, they care, and then they email support,” and treats delays to major providers as an operational incident, noting that “even a 30-second delay to Hotmail addresses gets us out of bed in the middle of the night,” according to Postmark’s deliverability documentation.

Practical requirements on the sending side:

  • Send magic link emails on a dedicated transactional stream, separate from marketing sends, the same separation any transactional email needs.
  • Authenticate the sending domain (SPF, DKIM, DMARC) so the message isn’t held up for filtering before it reaches the inbox.
  • Keep the email itself minimal: one link, one expiry statement, no images or tracking pixels that slow rendering or trip spam filters.
  • Disable click tracking on magic link emails. Link rewriting sends the raw token through the provider’s redirect domain and logs, and can itself trigger a prefetch.
  • Rate-limit link requests per address and IP, and show the same “check your inbox” message whether or not the account exists, so the form can’t be used to enumerate accounts.

If you’re sending magic links through the same email API you use for other transactional mail, a dedicated stream and consistent authentication matter more than which provider you pick. Coldletter, an email platform for SaaS teams with templating, automation and API integration, sends auth emails like this on a dedicated authenticated stream, separate from the lifecycle and marketing sends of the same account, for exactly this reason.

Frequently Asked Questions

What is a magic link email?

A magic link email is a passwordless login method: the app sends a single-use, time-limited link to the user’s email address, and clicking it authenticates them directly without a password or a code to type. The security depends entirely on how that link’s token is generated, stored, and invalidated.

How long should a magic link stay valid?

There’s no universal number, but shorter is safer. Supabase’s default is 1 hour, while NIST SP 800-63B requires out-of-band authentication to complete within 10 minutes, so 10 minutes or less is a defensible target for a link that is the entire login. Whatever window you choose, invalidate the token immediately on first use regardless of whether the expiry has passed.

Are magic links more secure than passwords?

They remove password-specific risks like reuse across sites and credential-stuffing attacks, since there’s no password to steal from another breach. But they introduce a different single point of failure: whoever controls the recipient’s inbox controls every magic link sent to it. Neither method is strictly safer in every scenario; they trade one attack surface for another.

Why did my magic link say it expired even though I only clicked it once?

The most common cause is a corporate, university, or hospital email security scanner that fetched the link to inspect it before the message reached the inbox, consuming the single-use token before the user ever clicked it. The reliable fix is a landing page that redeems the token only when the user presses a button (a POST request). A URL fragment alone is not enough, because scanners that run a headless browser can execute page JavaScript and read it.

Can I use magic links in a mobile app?

Yes, but the same-device requirement some implementations enforce becomes more visible on mobile, since a link opened from an email app often launches in a different default browser than the one that made the original request. Plan for a visible “resend the link” option rather than treating that mismatch as a rare edge case.

Should I use a magic link or an email OTP?

Both typically rely on the same kind of random, single-use token underneath; the difference is delivery format, plus the keyspace: a 6-digit code needs attempt limits that a 256-bit link token doesn’t. Magic links suit desktop-first, infrequent-login SaaS products where a single click is less friction than typing a code. Email OTP suits mobile-first or high-frequency login flows where the user may not have easy access to the device or inbox that received the link.