Skip to content

fix(auth): resolve GitHub OAuth error=github redirect loop#1299

Open
Mayur-e wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
Mayur-e:fix/github-oauth-redirect-loop
Open

fix(auth): resolve GitHub OAuth error=github redirect loop#1299
Mayur-e wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
Mayur-e:fix/github-oauth-redirect-loop

Conversation

@Mayur-e
Copy link
Copy Markdown

@Mayur-e Mayur-e commented May 27, 2026

What this fixes

Closes #1221

After clicking "Sign in with GitHub", users were redirected back to /auth/signin?error=github instead of the dashboard.

Root causes found & fixed

1. src/lib/auth.ts

  • Added supabaseAdmin null guard in signIn callback — when Supabase env vars are missing, calling .from() on null threw a TypeError that NextAuth silently converted to error=github
  • Wrapped DB operations in try/catch so transient errors never block login

2. src/app/auth/signin/page.tsx

  • Added AuthErrorBanner that shows a human-readable error message when ?error= is in the URL
  • Clears the error param from the URL after display to prevent stale errors on refresh
  • Wrapped useSearchParams() in <Suspense> for Next.js 14 compatibility

3. src/components/landing/LandingPage.tsx

  • Sign-in links used raw href="/api/auth/signin/github" bypassing NextAuth CSRF — changed to href="/auth/signin"

4. DEVELOPMENT.md

  • Added error=github troubleshooting checklist

Testing

  • npm run lint — no warnings or errors
  • npm run build — all 11 pages compiled
  • ✅ Tested locally: home → sign-in → GitHub OAuth → dashboard ✅

Screenshots

Before — URL shows error=github but no feedback given to user

download

After — Clean sign-in page on fresh visit

Screenshot 2026-05-27 164649

After — Successful login reaches dashboard

Screenshot 2026-05-27 164800
Video.webm

- Add supabaseAdmin null guard in signIn callback: when Supabase env vars
  are missing or contain placeholder values, supabaseAdmin is null and
  calling .from() on it throws a TypeError that NextAuth silently converts
  to error=github. Now logs a warning and returns true so auth succeeds
  with degraded functionality instead of crashing.

- Wrap Supabase upsert in try/catch: transient DB errors (table missing,
  network issues) no longer block authentication. Errors are logged to
  the server console for operator visibility.

- Add AuthErrorBanner to sign-in page: reads the ?error= query param via
  useSearchParams() and maps NextAuth error codes to human-readable
  messages (github, OAuthCallback, OAuthSignin, Configuration,
  AccessDenied). Wrapped in Suspense boundary for Next.js 14 static
  generation compatibility. Clears the param from the URL after display
  so stale errors do not persist across page refreshes.

- Fix landing page sign-in links: all CTA and nav links that previously
  used raw href to /api/auth/signin/github (bypassing NextAuth CSRF token
  validation and causing immediate error=github) now navigate to
  /auth/signin instead, preserving the intended UX flow.

- Expand DEVELOPMENT.md troubleshooting with a dedicated error=github
  redirect loop checklist covering all known root causes.

Fixes #<issue-number>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 27, 2026

@Mayur-e is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:docs GSSoC type bonus: documentation (+5 pts) type:security GSSoC type bonus: security (+20 pts) labels May 27, 2026
@github-actions
Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Priyanshu-byte-coder — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your first PR on DevTrack! 🎉

A maintainer will review it within 48 hours. While you wait:

  • Make sure CI is passing (type-check + lint)
  • Double-check the PR description is filled out and the issue is linked
  • Feel free to ask questions in Discussions if you need help

If you find DevTrack useful, a ⭐ star on the repo is always appreciated — it helps the project grow and attract more contributors!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:docs GSSoC type bonus: documentation (+5 pts) type:security GSSoC type bonus: security (+20 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] GitHub OAuth Error Redirect Loops Back to Sign-In Page

1 participant