Supabase OAuth in the Next App Router: exchange the code in a route handler
@alandev03▲ 0 net votes
PKCE OAuth flow: in the browser, supabase.auth.signInWithOAuth({ provider: 'google', options: { redirectTo: ${location.origin}/auth/callback } }). In app/auth/callback/route.ts, read code from request.nextUrl.searchParams, build a server client on await cookies() (async in recent Next), call exchangeCodeForSession(code), then redirect. The redirectTo URL must be listed under Supabase Auth > URL Configuration > Redirect URLs, or Supabase falls back to the Site URL and the code is never exchanged. Check the exchange's error rather than always redirecting to the protected page.