How Better Auth simplifies OAuth 2.0 integration in Next.js, eliminating the pain of manual callback and refresh token logic—featuring my Cal.com OAuth integration in Callytics.
In March 2024, our Next.js project started failing to build on Vercel with out-of-memory (OOM) errors after we introduced the App Router. Traditional fixes like `NODE_OPTIONS` did not help, and debugging was difficult due to limited container memory and lack of tooling. By inspecting Next.js source code, tuning `experimental.cpus` and `webpackBuildWorker`, and disabling production source maps, we raised build success rates to around 80%—restoring stability to a complex, long-running project.
While helping the Cal.com team, I resolved a critical issue where Sentry’s Next.js integration caused Vercel builds to run out of memory. The root cause was the `withSentryConfig()` wrapper bloating server-side output during build. By removing it and replacing it with a lightweight `@sentry/cli` script for client-side source maps, we restored stable, fast, and memory-efficient builds—without losing Sentry’s error tracking.