A clean, educational reference implementation of secure authentication for Cloudflare Workers inspired by Mark Volkmann and Scott Tolinski
This repository contains a minimal, well-documented, standards-compliant authentication foundation built for Cloudflare Workers using Hono, Turso (libSQL), PBKDF2 password hashing, JWT sessions, and secure session management.
Important
This project is primarily educational.
It demonstrates how to implement modern authentication correctly from first principles β following NIST SP 800-63B / SP 800-132 guidelines, OWASP recommendations, and Cloudflare Workers constraints.
For most real-world projects (especially if you want speed, maintainability, plugin ecosystem, OAuth/social providers, magic links, passkeys, multi-tenant support, rate limiting, etc.), you are much better served by using:
Better Auth β https://www.better-auth.com
(the most comprehensive, framework-agnostic authentication & authorization library for TypeScript in 2025β2026)
Better Auth gives you far more features out-of-the-box, better developer experience, a growing plugin ecosystem, and active maintenance β while still letting you stay in control of your database.
Use this repo if you want to:
- Deeply understand how secure auth works under the hood
- Learn NIST-compliant password storage, constant-time comparison, session revocation, sliding expiration, JWT refresh patterns
- Study a clean, auditable Apache-2.0 example built specifically for edge runtimes
- Teach/experiment with auth concepts
Use Better Auth if you want to ship a production application quickly and reliably.
- NIST SP 800-132 compliant PBKDF2-SHA384 password hashing + normalization + common-password checks
- Secure session management with device tracking (user-agent + IP)
- JWT access + refresh token pattern with session linkage (for revocation)
- HTTP-only, SameSite=Strict/Lax secure cookies
- Type-safe Hono middleware (
requireAuth) - Turso/libSQL schema + basic migration helpers
- Zod-based input validation
- Runtime security-focused tests (format validation, tampering resistance, unicode handling, timing-safe comparison)
- OAuth / social providers (use Better Auth for that)
- Passkeys / WebAuthn
- Magic links / OTP
- Multi-factor authentication (TOTP, etc.)
- Rate limiting (implement via Cloudflare or middleware)
- Advanced session analytics / audit logs
- Multi-tenancy
These are all excellent reasons to reach for Better Auth instead.
.
βββ apps/
β βββ cloudflare-workers/ # Example Worker + Hono routes
βββ packages/
β βββ auth/ # Core hashing, verification, session logic
β βββ errors/ # Shared error types
β βββ infrastructure/ # DB client + utilities
β βββ schemas/ # Zod schemas
β βββ types/ # Shared TypeScript types
βββ docs/
βββ adr/ # Architecture Decision Records
βββ audits/ # Security audits (generated using Claude)