Prompt

How do I send magic link login emails?

Technology / Api platforms3 observationsLast seen Nov 17, 2026

Latest observation

Nov 17, 2026OpenAI APIWeb search: off

To send magic link login emails, you generally need four pieces:

  1. A backend endpoint that creates a one-time login token
  2. A database or cache to store that token temporarily
  3. An email service to send the link
  4. A verification endpoint that consumes the token and logs the user in

Typical flow

  1. User enters their email address.
  2. Your server generates a secure, random token.
  3. Store a hashed version of the token with:
    • the user email or user ID
    • expiration time
    • one-time-use flag
  4. Email a link like:
https://yourapp.com/magic-login?token=abc123
  1. When the user clicks it:
    • your server checks the token
    • verifies it’s valid and unexpired
    • marks it as used
    • creates a session / JWT / auth cookie

Example implementation steps

1) Generate a secure token

Use a cryptographically secure random value.

import crypto from "crypto";

const token = crypto.randomBytes(32).toString("hex");

2) Store token securely

Prefer storing a hash of the token instead of the token itself.

const tokenHash = crypto.createHash("sha256").update(token).digest("hex");

Store:

  • email
  • tokenHash
  • expiresAt
  • usedAt (null until consumed)

3) Send the email

Use a transactional email provider such as:

  • SendGrid
  • Postmark
  • Mailgun
  • Amazon SES
  • Resend

Example email body:

Click to sign in:
https://yourapp.com/auth/magic?token=YOUR_TOKEN

This link expires in 15 minutes.
If you didn’t request this, ignore this email.

4) Verify token on click

When the link is visited:

  • hash the provided token
  • look it up in your DB
  • ensure it exists, is not expired, and not used
  • create a session
  • invalidate token

Example backend logic outline

Request magic link

app.post("/auth/magic-link", async (req, res) => {
  const { email } = req.body;

  const token = crypto.randomBytes(32).toString("hex");
  const tokenHash = crypto.createHash("sha256").update(token).digest("hex");

  await db.magicLinks.insert({
    email,
    tokenHash,
    expiresAt: new Date(Date.now() + 15 * 60 * 1000),
    usedAt: null,
  });

  const link = `https://yourapp.com/auth/magic?token=${token}`;

  await sendEmail(email, "Your login link", `Click here: ${link}`);

  res.json({ ok: true });
});

Verify magic link

app.get("/auth/magic", async (req, res) => {
  const { token } = req.query;
  const tokenHash = crypto.createHash("sha256").update(token).digest("hex");

  const record = await db.magicLinks.findOne({ tokenHash });

  if (!record || record.usedAt || record.expiresAt < new Date()) {
    return res.status(400).send("Invalid or expired link");
  }

  await db.magicLinks.update(record.id, { usedAt: new Date() });

  // Create session / set cookie / issue JWT
  req.session.userEmail = record.email;

  res.redirect("/dashboard");
});

Security best practices

  • Expire links quickly: 10–30 minutes is common
  • Use one-time-use tokens
  • Store hashed tokens, not raw tokens
  • Rate limit requests by IP/email
  • Avoid revealing whether an email exists if you care about account enumeration
  • Send from a verified domain
  • Protect against link forwarding if needed by binding to device/session signals (optional)

If you want the easiest path

Many auth providers already support magic links:

  • Clerk
  • Auth0
  • Supabase Auth
  • Firebase Auth
  • Magic.link
  • NextAuth (email provider)

If you tell me your stack (e.g. Node/Express, Next.js, Python/Django, Rails, etc.), I can give you a ready-to-use implementation.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (3 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.