What problem does it solve?
Addresses OAuth redirects, session management, and environment-scope pitfalls in Next.js App Router apps. Specifically, it tackles the build-time inlining issue caused by NEXT_PUBLIC_* variables that bakes localhost URLs into production bundles and provides guidance for runtime URL detection, dynamic base URLs, and secure cookie handling across development and production. It also outlines CSP considerations and Google OAuth configuration to prevent login failures.
Core Features & Use Cases
- Dynamic client/server URL detection to avoid build-time inlining (use window.location.origin on the client and BETTER_AUTH_URL (runtime) on the server).
- Google OAuth integration with proper redirect URIs, CSP, and trusted origins, plus Safe cookie attributes (SameSite lax and secure flag controlled by environment).
- API route integration with Next.js using toNextJsHandler for unified auth endpoints and a server-side session getter.
- Guidance for diagnosing and fixing common auth issues (redirect mismatches, session persistence, and production readiness).
Quick Start
Configure BETTER_AUTH_URL in production, set up Google OAuth credentials, and run the app to enable a robust, production-ready Next.js App Router authentication flow.