AI summary by TwinMind
The State of Authentication
Theo - t3․gg
1h 3m 22s
Three Pillars of Authentication
- Verification: Confirming user identity (who they say they are)
- User Info: User data, permissions, email, profile picture storage
- Authentication UI: Sign-in/out buttons, management pages, OAuth buttons
Verification Components
- Sign-in Methods: Username/password, passkeys, OAuth (Google, etc.), magic links
- State Storage/Verification:
- Access/refresh tokens (cookies, server-validated)
- JWTs (JSON Web Tokens in local storage, client-accessible)
OpenAuth Overview
- Created by: Dax and SST team
- Focus: Pure verification layer only - no user management
- Architecture: Centralized auth server on your infrastructure
- Limitations:
- No user info management
- No authentication UI (basic template available)
- Requires custom database integration
- Use Case: When you want to own all pieces but need modern OAuth verification
- Setup Time: ~2 days implementation
NextAuth/Auth.js Analysis
- Legacy Solution: Originally built for Next.js, now framework-agnostic
- Database Integration: Requires database adapter (Prisma, Drizzle, etc.)
- Major Limitation: Prisma adapter can't run on Edge (middleware issues)
- Database Schema Requirements:
- User table
- Account table
- Session table
- Verification token table
- Authenticator table
- Strengths:
- Extensive OAuth provider support (50+ providers)
- Handles complex OAuth quirks (e.g., Twitch non-standard refresh tokens)
- New Feature: Can now work without database using JWTs
- Positioning: Between user info and verification layers
Better Auth Deep Dive
- Modern Alternative: Less tech debt than NextAuth, TypeScript-first
- Database Required: Must store user data in your database
- Advanced Features:
- Organization management
- Access control
- Two-factor authentication
- Multi-tenancy
- Rate limiting
- Plugin System: Modular approach for features like:
- Username support
- Phone number verification
- Magic links
- Email OTP
- Passkeys
- Generic OAuth
- Framework Support: Better cross-framework support than NextAuth
- React Native: First open-source solution with decent React Native support
- Limitations:
- Custom fetch function required for mobile
- Limited to React Native/Expo (no Swift, Kotlin, Flutter)
- UI Generation: Copy-paste component generator (Shadcn approach)
- Google Compliance Issue: Generated components don't follow Google branding guidelines
Clerk Comprehensive Review
- Business Model: Well-funded SaaS, not fully open source
- Pricing:
- Free tier: 10,000 MAU
- Paid: $25/month + $0.02 per additional user
- Unique billing: Users count as active only after returning 24+ hours post-signup
- Platform Support: Extensive cross-platform coverage
- Next.js, React Native, Expo, Chrome extensions
- iOS, Node, Express, React Router, Remix
- Recently added Nuxt and Vue support
- Integration Speed: Under 5 minutes setup time
- Components:
- Pre-built UI components
- Major Issue: No server-side rendering (causes layout shifts)
- Many users end up building custom components
- Middleware:
- Runs on every request (performance impact)
- JWT revalidation every 60 seconds
- Can protect routes but author recommends against it
- User Data: Stored in Clerk's database, not yours
- API access to user data
- No direct database joins possible
- Webhook sync option available but rarely used
- OAuth Token Management: Can store and refresh OAuth tokens from providers
- Frustrations:
- Per-app pricing model (working on org-based pricing)
- Middleware performance overhead
- Component SSR limitations
- Missing Feature: Stripe integration announced April 2023, still not released after nearly a year
Better Auth vs NextAuth Positioning
- Better Auth: Modern, TypeScript-first, plugin architecture, better cross-framework support
- NextAuth: Mature, extensive provider support, more community resources, database optional
Lucia Auth (Deprecated)
- Status: Being deprecated by creator (Pilcrow)
- Reason: Creator now implements sessions from scratch, finds library approach frustrating
- Database Adapter Complexity: Significant maintenance burden
- Recommendation: Use Auth.js or Better Auth instead
- Middleware Philosophy: Strong stance against using middleware for route protection
Stack Auth Analysis
- Business Model: Fully open source alternative to Clerk
- Stage: Early development, expect more issues
- Self-hosting: Complete self-hosting capability
- Components: UI compliance with Google branding rules
- Pricing: Similar free tier to Clerk, different team pricing structure
- Self-hosting Complexity: Multiple interdependent services to manage
- Use Case: Want Clerk-like experience with exit strategy to self-hosting
Firebase Auth Warning
- Security Issues: Frequent misconfigurations lead to vulnerabilities
- Rate Limiting: Random aggressive rate limits affecting user sign-ins
- Exploit History: 900 sites, 125M accounts compromised due to common misconfigurations
- Recommendation: Avoid due to security and reliability concerns
Supabase Auth
- Integration: Built into Supabase platform for their permission model
- Limitations: Less full-featured than dedicated auth providers
- Use Case: When using Supabase ecosystem and need integrated auth
- Alternative Usage: Some use just for free auth, ignore database features
WorkOS Enterprise Focus
- Target Market: Enterprise clients with complex requirements
- Pricing:
- Custom domain: $100/month
- SSO (SAML/OIDC): $125/month per connection
- Features: Advanced enterprise auth requirements
- AuthKit: Open-source component library (can integrate with other providers)
- Use Case: When targeting large enterprise customers (Microsoft, etc.)
Next.js Future Features (Canary)
- Unauthorized Function: New primitive for handling auth failures
- Request Interceptors: Route-specific auth without global middleware
- Benefits:
- Avoid middleware performance overhead
- Page-specific auth logic
- Better than current layout-based approaches
- Limitation: No Edge runtime support yet
Authentication Method Preferences
- OAuth: Preferred method
- Passkeys: Acceptable but UX needs improvement
- Magic Links: Secure but annoying UX
- Username/Password: Strongly discouraged
- Major security risk
- Expensive support overhead
- Poor user experience
- Implementation complexity
JWT Implementation Best Practices
- Clerk's Approach: 60-second expiration to allow quick invalidation
- Problem: Standard JWTs can't be invalidated until expiration
- Solution: Short expiration windows balance security and performance
- Benefit: Reduces server round-trips while maintaining security
Final Recommendations
- OpenAuth: Want simple OAuth, deploy yourself, okay with standalone service
- Better Auth: Want data in your DB, need modern features, willing to integrate yourself
- Auth.js: Don't want data in DB, need extensive provider support
- Clerk: Want it to work everywhere, don't mind paying, fastest setup
- Stack Auth: Like Clerk but want exit strategy, okay with early-stage product
- WorkOS: Enterprise customers spending $10k+/month, need advanced compliance features
