workers-auth
Drop-in authentication and authorization for Cloudflare Workers. Magic links, GitHub OAuth, RBAC, sessions — all running on the edge.
Why workers-auth?
Section titled “Why workers-auth?”workers-auth gives you a complete auth system for Cloudflare Workers with zero external services beyond what you already have on Cloudflare.
- Authentication strategies — Magic link emails and GitHub OAuth, with a pluggable interface for custom strategies
- Authorization — Role-based access control (RBAC) with wildcard permissions
- Edge-native storage — D1 for users/sessions, KV for fast session caching
- Hono middleware —
authenticateandauthorizemiddleware that plug directly into your Hono app - Pluggable architecture — Swap adapters, providers, and strategies without changing your app code
Install
Section titled “Install”npm install workers-auth honoQuick example
Section titled “Quick example”import { WorkersAuth } from 'workers-auth';import { MagicLinkStrategy } from 'workers-auth/authn/magic-link';import { D1Adapter } from 'workers-auth/adapters/d1';import { KVAdapter } from 'workers-auth/adapters/kv';
const auth = WorkersAuth({ database: (binding) => D1Adapter(binding), cache: (binding) => KVAdapter(binding), authn: { strategies: [MagicLinkStrategy({ provider, template })] }, redirectUrl: '/dashboard',});
app.route('/auth', auth.handler);app.use('/api/*', auth.authenticate);Ready to set up? Head to the Quick Start guide.