Skip to content

fix(auth): restore SSR OAuth functionality broken in v2.91.0#2039

Merged
mandarini merged 1 commit intosupabase:masterfrom
7ttp:revert-2014-fix/exchange-code-deadlock
Jan 21, 2026
Merged

fix(auth): restore SSR OAuth functionality broken in v2.91.0#2039
mandarini merged 1 commit intosupabase:masterfrom
7ttp:revert-2014-fix/exchange-code-deadlock

Conversation

@7ttp
Copy link
Contributor

@7ttp 7ttp commented Jan 20, 2026

Summary

Reverts #2014 which broke OAuth authentication in SSR/serverless environments.

Problem

PR #2014 added setTimeout(..., 0) to defer SIGNED_IN event notifications in exchangeCodeForSession. While this prevented a deadlock in some scenarios, it introduced a critical regression:

In serverless/SSR environments (Next.js, Vercel, etc.):

  • OAuth callbacks rely on exchangeCodeForSession to trigger auth state change listeners
  • These listeners (via @supabase/ssr) write auth cookies during the request
  • setTimeout(..., 0) defers execution to the next event loop tick
  • The serverless function completes and returns the response before the deferred callback runs
  • Result: No auth cookies are set, OAuth login fails

User Impact:

  • OAuth login (Google, etc.) stopped working after upgrading from v2.90.1 to v2.91.0
  • Users are redirected but remain logged out
  • OTP auth continues to work (unaffected)

Solution

The deadlock issue that #2014 attempted to fix is properly addressed by #2016, which makes _notifyAllSubscribers non-blocking by removing await on subscriber callbacks. This approach:

✅ Prevents deadlocks when callbacks perform async operations like getUser() or getSession()
✅ Keeps notifications synchronous so SSR cookie adapters work correctly
✅ Fixes the root cause instead of working around it with setTimeout

Related

@7ttp 7ttp requested review from a team as code owners January 20, 2026 21:04
@7ttp 7ttp changed the title Revert "fix(auth): defer subscriber notification in exchangeCodeForSession to prevent deadlock" fix(auth): restore SSR OAuth functionality broken in v2.91.0 Jan 20, 2026
@7ttp
Copy link
Contributor Author

7ttp commented Jan 20, 2026

@mandarini
can you please have a look at #2016 before reviewing this! 💚

@mandarini mandarini merged commit 746c76a into supabase:master Jan 21, 2026
24 of 25 checks passed
ryugibo added a commit to ryugibo/ryugibo.com that referenced this pull request Jan 29, 2026
- supabase/supabase-js#2039
- pnpm update -r @supabase/supabase-js --latest
joschka-w added a commit to joschka-w/pocket-dex that referenced this pull request Jan 30, 2026
joschka-w added a commit to joschka-w/pocket-dex that referenced this pull request Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Breaking behavior change: exchangeCodeForSession defers SIGNED_IN event in v2.91.0, impacting OAuth cookie writes in SSR/serverless

2 participants