v0.1.0 — Published on npm

Auth for Cloudflare
Workers.

D1 + KV + Workers. Email/password, magic links, OTP, and OAuth — production-grade authentication built entirely for the edge. No Node.js. No external services.

gately-auth — VS Code
Explorer
📁 packages
📄 core/src/auth.ts
📄 client/src/index.ts
📄 cli/src/index.ts
📁 examples
📄 basic-worker/src/worker.ts
📁 docs
📄 src/pages/index.astro
📄 package.json
📄 wrangler.toml
packages/core/src/auth.ts
packages/client/src/index.ts
examples/basic-worker/src/worker.ts
1import { gatelyAuth } from '@gately/auth-core'
2import { createD1Adapter, createKVStore } from '@gately/auth-core/adapters'
3import { gatelyEmail } from '@gately/auth-core/plugins'
4
5export interface Env {
6 AUTH_DB: D1Database
7 AUTH_KV: KVNamespace
8 AUTH_SECRET: string
9 GATELY_API_KEY: string
10}
11
12export function createAuth(env: Env) {
13 return gatelyAuth({
14 secret: env.AUTH_SECRET,
Project overview

Edge auth runtime

Session handling, D1 persistence, KV caching, and plugin integration for Cloudflare Workers.

Auth routes14
Adapters2
Providers5
Active file

packages/core/src/auth.ts

Secure configuration for cookies, OAuth, magic links, and OTP flows.

$pnpm dev
Local server ready on http://127.0.0.1:8787
Watching packages/core, packages/client, and examples/basic-worker
main • 3 files changed Cloudflare Workers • ready

Install

Get started in seconds.

Pick your package manager or use an AI agent prompt to scaffold everything automatically.

npm pnpm yarn bun
$npm install @gately/auth-core @gately/auth-client
Agent Prompt
Kiro / Cursor / Copilot
Set up gately-auth in this Cloudflare Worker project. Install @gately/auth-core and @gately/auth-client. Create src/auth.ts using gatelyAuth() with createD1Adapter(env.AUTH_DB), createKVStore(env.AUTH_KV), and the gatelyEmail plugin. Enable emailAndPassword with requireEmailVerification: false. Mount auth.handler(request) on all /auth/* routes in the Worker fetch handler. Add the D1 and KV bindings to wrangler.toml. Run the CLI to generate and apply migrations.
MCP Server
Coming soon
$npx @gately/auth-mcp start --project my-app
Agent Skill
Coming soon
$npx @gately/auth-cli skill add sign-in-with-google --project my-app

Setup in 30 seconds

Two files. Done.

Create your auth instance, mount the handler. Every auth route — sign-up, sign-in, OTP, OAuth — is handled automatically.

src/auth.tsTypeScript
import { gatelyAuth } from '@gately/auth-core'
import { createD1Adapter, createKVStore } from '@gately/auth-core/adapters'
import { gatelyEmail } from '@gately/auth-core/plugins'

export function createAuth(env: Env) {
  return gatelyAuth({
    secret: env.AUTH_SECRET,
    db: createD1Adapter(env.AUTH_DB),
    kv: createKVStore(env.AUTH_KV),
    emailAndPassword: { enabled: true },
    plugins: [gatelyEmail({ apiKey: env.GATELY_API_KEY })],
  })
}
src/worker.tsTypeScript
import { createAuth } from './auth'

export default {
  async fetch(req: Request, env: Env) {
    const auth = createAuth(env)

    // Mount all /auth/* routes
    return auth.handler(req)
  },
}

// Protect any route server-side
const session = await auth.api.getSession(req)
if (!session) return new Response('401', { status: 401 })

API Surface

Every route, out of the box.

Mount on /auth/* and all endpoints are live immediately.

POST/auth/sign-up/email
POST/auth/sign-in/email
POST/auth/sign-out
GET/auth/session
POST/auth/magic-link/send
GET/auth/magic-link/verify
POST/auth/otp/send
POST/auth/otp/verify
GET/auth/verify-email
GET/auth/oauth/:provider
GET/auth/oauth/:provider/callback
POST/auth/password/reset
POST/auth/password/reset/confirm
GET/auth/sessions
DELETE/auth/sessions/:token
DELETE/auth/sessions
GET/auth/health
GET/auth/username/check

Extensible

Official plugins.

Drop-in plugins that extend schema, routes, and email — without forking the core.

Gately Email

Connect to Gately's transactional email platform. Handles password reset, magic links, OTP, and verification automatically.

Admin Plugin

Protected /auth/admin/* endpoints for user listing, banning, session revocation, and deletion. X-Admin-Key required.

Username Plugin

Adds a unique username field to sign-up. Validation, uniqueness check, and a public availability endpoint included.

Google One Tap

Exchange a Google ID token for a gately-auth session — no redirect flow. Works with the One Tap JS snippet.

Social sign-in

Every OAuth provider.

Configure any OAuth 2.0 provider in one object. PKCE, state validation, and profile mapping handled automatically.

+ Any OAuth 2.0 / OIDC provider via socialProviders config

Roadmap

What's coming.

The next layer — build agents, MCP servers, CLI tools, and skills that connect directly to the Gately Auth platform.

Coming soon

Agent Framework

Build AI agents that authenticate on behalf of users. Session-aware, permission-scoped, deployable to Workers.

Coming soon

MCP Servers

Model Context Protocol servers for Gately Auth. Give AI assistants secure, authenticated access to your auth data.

Coming soon

Skills

Composable auth capabilities — "sign in with Google", "verify OTP", "get session" — that agents invoke directly.

Coming soon

Extended CLI

Agent-powered CLI. Describe what you need in plain language — the CLI scaffolds, migrates, and deploys for you.

Getting started

Three steps.

From install to a working auth Worker — in under 5 minutes.

01

Create your instance

Call gatelyAuth() with your D1 binding, KV namespace, and secret. One function, fully typed, zero globals.

02

Mount the handler

Route /auth/* to auth.handler(request). Works with Hono, plain Workers, itty-router, or any fetch handler.

03

Use the client SDK

Install @gately/auth-client in your frontend. React hooks, typed methods, automatic cookie/token management.

Compatibility

Works with your stack.

HonoNext.jsSvelteKit RemixAstroReact Vueitty-routerCloudflare Workers Cloudflare Pages

Monorepo

The packages.

A focused set — nothing more, nothing less.

@gately/auth-coreWorker handler, D1/KV adapters, all auth providers and plugins0.1.0
@gately/auth-clientBrowser SDK with React hooks and session management0.1.0
@gately/auth-cliCLI — scaffold, login to Cloudflare, auto-provision D1/KV, migrate, deploy0.1.0
@gately/auth-mcpMCP server runtime for agent-aware auth automation0.1.0
@gately/auth-skillsComposable auth skills for login, session, and user workflows0.1.0

Ready to ship?

Get authentication running in your Cloudflare Worker in under 5 minutes. No account required to get started.