Introduction
Himayah is a lightweight, type-safe, schema-first, and Edge-compatible authentication framework for modern TypeScript applications.

What is Himayah?
Himayah (حماية — Arabic for protection) is a framework-agnostic, schema-first TypeScript authentication library built for the modern web. Unlike monolithic auth providers, Himayah gives you complete ownership over your schema, your database, and your code — while handling all cryptographic, session, and rate-limiting complexities securely.
Why Himayah?
Most auth libraries force you into one of two traps: either you give up full control to a third-party service, or you end up with a massive dependency that does too much magic. Himayah takes a different approach.
You own the schema
Himayah never touches your migrations. Define your tables, map them to our thin adapters, and you're done.
Runs anywhere
No Node.js-only crypto or fs calls. Runs natively on Cloudflare Workers, Vercel Edge, Deno, Bun, and traditional Node.
Composable by design
Pick exactly the plugins you need — password, OAuth, magic link, OTP, passkeys, or organizations. No tree-shaking puzzles.
Production-hardened security
PBKDF2-derived AES-256-GCM JWE sessions, constant-time comparisons, double-submit CSRF, and PKCE for OAuth. Secure by default.
Core Concepts
Session Model
Himayah sessions are stateless JWE tokens by default. The session pipeline works in two steps:
- PBKDF2-SHA256 stretches your
AUTH_SECRETstring into a proper 32-byte cryptographic key (100,000 iterations) - AES-256-GCM uses that derived key to encrypt the session payload client-side inside an
HttpOnlycookie
Think of PBKDF2 as the key factory and AES-256-GCM as the vault. Both are needed — PBKDF2 creates the key, AES-256-GCM uses it to encrypt.
If you need immediate session revocation (e.g., after a password change or account ban), you can opt into stateful database sessions:
Plugin System
Every auth method is a plugin. Plugins register their own HTTP endpoints, validate inputs, and interact with the adapter. You compose them freely:
Adapter Pattern
Himayah defines a minimal set of database operations through the HimayahAdapter interface. Official adapters (Drizzle, Prisma, Kysely) implement this interface and map your existing schema tables to it.
You are never locked in. Because the adapter is a plain TypeScript interface, you can write a custom adapter for any database — MongoDB, Supabase, PlanetScale, etc.
Package Overview
| Package | Purpose |
|---|---|
@himayah/core | Composition engine, router, CSRF, session reading |
@himayah/session | JWE/JWS sessions, cookie utilities, stateful sessions |
@himayah/adapter | Base adapter interface and shared types |
@himayah/client | Type-safe browser API client |
@himayah/plugin-password | Email + password credentials (PBKDF2-SHA256) |
@himayah/plugin-oauth | OAuth 2.0 + OIDC with PKCE and state verification |
@himayah/plugin-magic-link | Passwordless email verification tokens |
@himayah/plugin-otp | SMS/email one-time passcodes |
@himayah/plugin-passkey | WebAuthn biometric credentials |
@himayah/plugin-organization | Multi-tenant orgs with roles and invitations |
@himayah/middleware-hono | Hono middleware adapter |
@himayah/middleware-express | Express middleware adapter |
@himayah/adapter-drizzle | Drizzle ORM adapter |
@himayah/adapter-prisma | Prisma Client adapter |
@himayah/adapter-kysely | Kysely query builder adapter |
@himayah/rate-limit-redis | Redis-backed distributed rate limiting |
Next Steps
Getting Started →
Install packages, set up your schema, and have auth running in 10 minutes.
Architecture →
Understand the session model, request lifecycle, and plugin composition.
Auth Plugins →
Explore password, OAuth, magic link, OTP, passkey, and org plugins.
Database Adapters →
Connect your Drizzle, Prisma, or Kysely schema.