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

Closed
opened 2026-04-13 09:32:15 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/5953

State: closed
Merged: No


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.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5953 **State:** closed **Merged:** No --- # 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. -->
GiteaMirror added the pull-request label 2026-04-13 09:32:15 -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#14593