---
title: Magic link authentication
description: Passwordless login system using magic links sent via email with JWT tokens and session management.
image: https://developers.cloudflare.com/dev-products-preview.png
---

> Documentation Index  
> Fetch the complete documentation index at: https://developers.cloudflare.com/email-service/llms.txt  
> Use this file to discover all available pages before exploring further. 

[Skip to content](#%5Ftop) 

# Magic link authentication

Implement passwordless authentication by sending secure, time-limited login links via email.

This example demonstrates how to send a magic link email for passwordless authentication using Cloudflare Email Service.

Configure the email binding in your Wrangler configuration file:

* [  wrangler.jsonc ](#tab-panel-8843)
* [  wrangler.toml ](#tab-panel-8844)

JSONC

```
{  "send_email": [{ "name": "EMAIL" }],  "vars": {    "DOMAIN": "yourdomain.com",  },}
```

TOML

```
[[send_email]]name = "EMAIL"
[vars]DOMAIN = "yourdomain.com"
```

The Worker exposes a `POST /send-magic-link` route that validates the submitted email address, generates a single-use token, and emails the recipient a time-limited login link. The following code implements that handler.

TypeScript

```
interface Env {  EMAIL: SendEmail;  DOMAIN: string;}
export default {  async fetch(request: Request, env: Env): Promise<Response> {    const url = new URL(request.url);
    if (url.pathname === "/send-magic-link" && request.method === "POST") {      return handleSendMagicLink(request, env);    }
    return new Response("Not Found", { status: 404 });  },};
async function handleSendMagicLink(  request: Request,  env: Env,): Promise<Response> {  const { email } = await request.json();
  if (!email || !isValidEmail(email)) {    return new Response(JSON.stringify({ error: "Invalid email" }), {      status: 400,    });  }
  // Generate a simple secure token (you would implement proper JWT/token handling)  const token = crypto.randomUUID();  const magicUrl = `https://${env.DOMAIN}/login?token=${token}`;
  // Send magic link email  await env.EMAIL.send({    to: email,    from: `noreply@${env.DOMAIN}`,    subject: "Your login link",    html: `      <h1>Login to your account</h1>      <p>Click the link below to log in:</p>      <p><a href="https://developers.cloudflare.com/email-service/examples/email-sending/magic-link/%3C/span%3E%3Cspan%20style="--0:#89DDFF;--1:#007474">${magicUrl}">Login Now</a></p>      <p>This link expires in 15 minutes.</p>    `,    text: `      Login to your account
      Click this link to log in: ${magicUrl}
      This link expires in 15 minutes.    `,  });
  return new Response(    JSON.stringify({      success: true,      message: "Magic link sent to your email",    }),  );}
function isValidEmail(email: string): boolean {  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);}
```

## Next steps

* [User signup flow](https://developers.cloudflare.com/email-service/examples/email-sending/signup-flow/) — combine magic links with account verification.
* [Send method](https://developers.cloudflare.com/email-service/api/send-emails/workers-api/) — full reference for the `send()` method.
* [Email headers](https://developers.cloudflare.com/email-service/reference/headers/) — add tracking or list-management headers.

```json
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/email-service/examples/email-sending/magic-link/#page","headline":"Magic link authentication · Cloudflare Email Service docs","description":"Passwordless login system using magic links sent via email with JWT tokens and session management.","url":"https://developers.cloudflare.com/email-service/examples/email-sending/magic-link/","inLanguage":"en","image":"https://developers.cloudflare.com/dev-products-preview.png","dateModified":"2026-06-09","publisher":{"@type":"Organization","name":"Cloudflare","url":"https://www.cloudflare.com/"},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"/directory/","name":"Directory"}},{"@type":"ListItem","position":2,"item":{"@id":"/email-service/","name":"Email Service"}},{"@type":"ListItem","position":3,"item":{"@id":"/email-service/examples/","name":"Examples"}},{"@type":"ListItem","position":4,"item":{"@id":"/email-service/examples/email-sending/","name":"Email sending"}},{"@type":"ListItem","position":5,"item":{"@id":"/email-service/examples/email-sending/magic-link/","name":"Magic link authentication"}}]}
```
