APIs & Data Architecture Auth & Security
21. Modern Authentication, Passkeys & Better Auth
Implement passwordless biometric passkeys, secure HttpOnly cookie session rotation, and modular authentication plugins with Better Auth.
better-auth.ts
typescript
import { betterAuth } from 'better-auth';import { passkey } from 'better-auth/plugins/passkey';import { drizzleAdapter } from 'better-auth/adapters/drizzle';import { db } from '#lib/server/db';export const auth = betterAuth({ database: drizzleAdapter(db, { provider: 'pg' }), emailAndPassword: { enabled: true }, session: { cookieCache: { enabled: true, maxAge: 300 }, cookie: { httpOnly: true, // Immune to JavaScript XSS exfiltration secure: true, // HTTPS only sameSite: 'lax' } }, plugins: [ passkey({ rpID: 'web-engine26.pages.dev', rpName: 'Web Engine 2026' }) ]});Modern Authentication, Passkeys & Better Auth
Better Auth provides a comprehensive TypeScript authentication runtime with passwordless WebAuthn passkeys, HttpOnly cookie rotation, and organisation multi-tenancy.
- Passkeys (WebAuthn): Asymmetric public-private keypairs anchored in hardware secure enclaves (TouchID, FaceID, Windows Hello) that are immune to phishing.
- HttpOnly Session Cookies: Completely isolated from client JavaScript (
document.cookie), protecting session tokens against XSS exfiltration. - Schema Ownership: Better Auth creates native Drizzle tables in your own database without third-party auth vendor lock-in.
Better Auth Session Visualiser Unauthenticated
Select Authentication Strategy:
WebAuthn Hardware Handshake Public-Key Cryptography
Authentication Architecture & GitHub Integration Identity Strategy
GitHub App (Modern Standard)
Fine-Grained Installation Token (JWT)99% (Strict Least Privilege)
Credential Liability:
Zero password storage; per-repository access tokens
Best For:
CI/CD bots, developer tooling, multi-tenant SaaS integrations
Key Properties:
- • Fine-grained repository permissions (e.g. read PRs only on org/repo)
- • Short-lived 1-hour installation tokens minted via private RSA key
- • Higher API rate limits (up to 15,000 req/hr)