Walk me through a magic link login system and its security considerations

Tests auth architecture and threat modeling for passwordless flows. Strong answers map request-token-email-verify-session, then harden with short expiry, single-use tokens, rate limits, and device binding.
What's really being asked
This question tests whether you can design a distributed authentication flow that balances growth goals with security rigor. Interviewers want to see that you understand token lifecycle management, session hygiene, and threat modeling in an email-based passwordless system rather than treating it as a simple send a link feature.
The full answer
First, the request phase: the user submits an email, the backend checks for account existence without revealing it via timing or error messages to prevent enumeration, then generates a high-entropy cryptographically random token stored hashed in a short-lived table. Second, delivery: the token is embedded in a HTTPS URL and sent via email over TLS; the plaintext token never leaves the server unhashed. Third, consumption: clicking the link sends the token to a validation endpoint that checks expiry typically 15 minutes or less, confirms the token hash matches, marks it consumed immediately to prevent replay, and then creates an authenticated session. Fourth, hardening: rate limiting on both request and validation endpoints to slow brute force and abuse, device or IP binding for the session to reduce token forwarding risk, and clear fallback paths for expired or undelivered links. Fifth, revocation: the ability to invalidate outstanding tokens on suspicious activity or email compromise.
The mistakes people make
Treating the magic link as a long-lived bearer credential that replaces a password rather than a single-use bootstrap mechanism. Storing tokens as plain text or using short predictable strings instead of 128-plus bit random values. Proposing JWTs for the magic link token, which complicates revocation and encourages longer lifetimes. Ignoring the risk of email interception by omitting TLS requirements or failing to mention that email is generally not a confidential channel. Forgetting to handle the race condition where a user clicks the link multiple times or forwards it to another device.
What usually comes next
How would you handle a user requesting multiple links in quick succession? Would you invalidate previous tokens or allow a small window of parallel valid tokens? How do you prevent an attacker from using the link on a different device if the user forwards it? What happens if the email provider scans the link and pre-fetches it, consuming the token before the user clicks? How would you combine magic links with multi-factor authentication for high-risk actions?
A concrete example
A senior candidate might describe a flow where the token is a 256-bit random value hashed with SHA-256 and stored in Redis with a 900 second TTL. On request, the system checks a per-email rate limit of five requests per hour. The email contains a URL like app.com/auth/magic with the plaintext token as a query parameter. When consumed, the endpoint hashes the incoming token, looks it up in Redis, deletes the key immediately on match, issues an HTTP-only SameSite strict session cookie, and rotates the session ID. If the user agent or IP differs significantly from the request phase, the system requires an additional OTP step before full authentication.
Interview question
In a secure magic link flow, what must the server do immediately after validating the token?
- a.Convert the valid token into a long-lived JWT session credential
- b.Immediately mark the token consumed and invalidate it before establishing the sessionCorrect
- c.Allow a brief idempotent reuse window to accommodate accidental double-clicks
- d.Extend the token's remaining TTL to match the new session length
Why? this is the answer
The token must be treated as a single-use bootstrap, consumed immediately to prevent replay. A reuse window is dangerous because email security scanners may pre-fetch the link, burning the token before the legitimate user clicks.
Just read this? Test yourself on what you have been reading.
Read the original → loginradius.com
- #authentication
- #security
- #passwordless
- #growth
- #system-design
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on authentication — each one lists the topics its interview covers.
See open roles