Prompt

How do I implement magic link login for customers?

Technology / Identity & Access2 observationsLast seen Nov 1, 2026

Latest observation

Nov 1, 2026OpenAI APIWeb search: off

A good magic-link login flow for customers usually looks like this:

1) User enters email

Customer submits their email address on a “Log in” form.

2) Create a one-time login token

On the backend:

  • generate a cryptographically random token
  • store only a hashed version of it in your database
  • attach metadata:
    • user/customer ID or email
    • expiration time (e.g. 10–20 minutes)
    • used/revoked flag
    • optional: IP/user-agent for auditing

3) Email the link

Send an email containing a URL like:

https://yourapp.com/magic-login?token=RANDOM_TOKEN

Or better, use a path like:

https://yourapp.com/auth/magic/confirm?token=RANDOM_TOKEN

4) Verify token when clicked

When the user opens the link:

  • hash the received token
  • look it up in your DB
  • ensure it exists, is unexpired, and unused
  • mark it as used immediately
  • create a session or issue a JWT
  • redirect the user into the app

5) Set a secure session

Prefer a secure, httpOnly cookie session over putting auth info in the URL or localStorage.


Recommended implementation details

Token generation

Use a secure random value, at least 32 bytes.

Example:

  • raw token: base64url(randomBytes(32))
  • store: sha256(token)

Why hash it? If your DB leaks, attackers can’t use the login links directly.

Expiration

Keep the token short-lived:

  • 10 minutes is common
  • 15 minutes is also fine

Single use

Once a token is used, invalidate it immediately.

Rate limiting

Protect the request endpoint:

  • limit by IP
  • limit by email address
  • prevent enumeration by always returning a generic response like:
    • “If an account exists, we’ve sent a login link.”

Session creation

After verification:

  • create server-side session
  • set cookie:
    • HttpOnly
    • Secure
    • SameSite=Lax or Strict depending on your flow

Minimal flow example

Request link

POST /auth/magic/request

Body:

{ "email": "customer@example.com" }

Backend:

  1. find user by email
  2. generate token
  3. store hashed token + expiry
  4. email link
  5. return generic success

Confirm link

GET /auth/magic/confirm?token=...

Backend:

  1. hash token
  2. verify record
  3. check expiry/unused
  4. create session
  5. redirect to dashboard

Security tips

  • Don’t reveal whether an email exists in the system
  • Use HTTPS only
  • Make tokens long and random
  • Invalidate on use
  • Consider tying token use to a rough device/IP fingerprint if your UX allows it
  • Log events for abuse detection
  • Add “resend link” cooldowns

Common pitfalls

  • Storing raw tokens in DB: avoid this
  • Long-lived magic links: risky
  • No rate limit: easy to abuse
  • Putting auth data in the URL permanently: clear it after login
  • Allowing token reuse: dangerous

Optional enhancements

  • Show a confirmation page after clicking the link before logging in
  • Support “login from same browser” checks
  • Offer fallback password login
  • Add WebAuthn/passkeys later for stronger auth

If you want, I can give you:

  1. a Node/Express implementation,
  2. a Django implementation, or
  3. a database schema + email template for magic links.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (2 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.