[PR #5953] [CLOSED] fix: prevent double OAuth callback in Next.js 16 #6346

Closed
opened 2026-03-13 12:55:33 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5953
Author: @sanki92
Created: 11/13/2025
Status: Closed

Base: canaryHead: fix/nextjs-16-oauth-double-callback


📝 Commits (2)

  • 05f53c3 fix: prevent double OAuth callback in Next.js 16
  • 8e3af59 refactor: simplify callback parsing

📊 Changes

1 file changed (+4 additions, -20 deletions)

View changed files

📝 packages/better-auth/src/api/routes/callback.ts (+4 -20)

📄 Description

Fix OAuth Double Callback in Next.js 16

Fixes #5658

Problem

OAuth callbacks were failing with please_restart_the_process error after upgrading to Next.js 16. The callback was getting triggered twice - first one succeeded, second one failed because the state was already consumed.

Changes

  • Removed POST→GET redirect in OAuth callback handler
  • Handle POST requests directly by merging body and query params
  • Prevents double invocation that was causing state mismatch errors

Why this works

The old code redirected POST to GET to ensure cookies were sent properly. In Next.js 16, this redirect triggers the callback twice. By handling POST directly, we avoid the extra round-trip while still supporting both methods.

Testing

  • OAuth social login tests pass
  • Link account tests pass
  • Build succeeds with no errors
  • Compatible with both GET and POST callback methods

Checklist

  • Code builds without errors
  • Tests pass
  • No breaking changes

Summary by cubic

Prevented double OAuth callbacks in Next.js 16 by handling POST requests directly and merging body + query params. This fixes state mismatch errors and restores reliable social login and account linking.

  • Bug Fixes
    • Removed POST→GET redirect in the OAuth callback handler to avoid double invocation.
    • Parse POST body and query together to keep compatibility and prevent please_restart_the_process errors.

Written for commit 8e3af59414. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5953 **Author:** [@sanki92](https://github.com/sanki92) **Created:** 11/13/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/nextjs-16-oauth-double-callback` --- ### 📝 Commits (2) - [`05f53c3`](https://github.com/better-auth/better-auth/commit/05f53c3778bf871d30e161b1fcc8bc35c4dbf908) fix: prevent double OAuth callback in Next.js 16 - [`8e3af59`](https://github.com/better-auth/better-auth/commit/8e3af59414a8528ef043afb4abd2dca8a8e998d1) refactor: simplify callback parsing ### 📊 Changes **1 file changed** (+4 additions, -20 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/callback.ts` (+4 -20) </details> ### 📄 Description # Fix OAuth Double Callback in Next.js 16 Fixes #5658 ## Problem OAuth callbacks were failing with `please_restart_the_process` error after upgrading to Next.js 16. The callback was getting triggered twice - first one succeeded, second one failed because the state was already consumed. ## Changes - Removed POST→GET redirect in OAuth callback handler - Handle POST requests directly by merging body and query params - Prevents double invocation that was causing state mismatch errors ## Why this works The old code redirected POST to GET to ensure cookies were sent properly. In Next.js 16, this redirect triggers the callback twice. By handling POST directly, we avoid the extra round-trip while still supporting both methods. ## Testing - [x] OAuth social login tests pass - [x] Link account tests pass - [x] Build succeeds with no errors - [x] Compatible with both GET and POST callback methods ## Checklist - [x] Code builds without errors - [x] Tests pass - [x] No breaking changes <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Prevented double OAuth callbacks in Next.js 16 by handling POST requests directly and merging body + query params. This fixes state mismatch errors and restores reliable social login and account linking. - **Bug Fixes** - Removed POST→GET redirect in the OAuth callback handler to avoid double invocation. - Parse POST body and query together to keep compatibility and prevent please_restart_the_process errors. <sup>Written for commit 8e3af59414a8528ef043afb4abd2dca8a8e998d1. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:55:33 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#6346