Skip to content

feat: detect revoked GitHub token and prompt re-authentication#1920

Open
Subhra-Nandi wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
Subhra-Nandi:feat/detect-revoked-github-token
Open

feat: detect revoked GitHub token and prompt re-authentication#1920
Subhra-Nandi wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
Subhra-Nandi:feat/detect-revoked-github-token

Conversation

@Subhra-Nandi
Copy link
Copy Markdown
Contributor

Summary

Closes #884

The JWT callback in auth.ts already validates the stored token every 24h
and sets session.error = "TokenRevoked" when GitHub returns 401. This PR
completes the user-facing side — detecting that flag and redirecting the user
to sign in with a clear message instead of silently showing empty widgets.

Changes

File Change
src/app/auth/signin/page.tsx Add TokenRevoked to AUTH_ERROR_MESSAGES
src/components/TokenRevokedGuard.tsx New — client component, signs out and redirects on revocation
src/app/dashboard/page.tsx Mount TokenRevokedGuard
package.json Add missing rehype-sanitize dependency

How It Works

  1. User revokes DevTrack access in GitHub Settings → Applications
  2. Within 24h the jwt callback hits GET /api.github.com/user → gets 401
  3. token.error = "TokenRevoked" is set on the JWT
  4. session.error = "TokenRevoked" is surfaced to the client
  5. TokenRevokedGuard detects this and calls signOut({ callbackUrl: "/auth/signin?error=TokenRevoked" })
  6. Signin page shows: "Your GitHub access was revoked. Please sign in again to continue."

What Was Already There (untouched)

  • auth.ts — full token validation logic ✅
  • next-auth.d.ts — types for session.error
  • error-utils.ts — safe error message string ✅
  • wrapped/page.tsx — already handles TokenRevoked

Screenshots

- Add TokenRevoked to AUTH_ERROR_MESSAGES in signin page showing
  'Your GitHub access was revoked. Please sign in again to continue.'
- Add TokenRevokedGuard client component that watches session.error
  and calls signOut() redirecting to /auth/signin?error=TokenRevoked
- Mount TokenRevokedGuard in dashboard page
- Install rehype-sanitize (missing dep, unrelated to this feature)

The jwt callback in auth.ts already sets token.error = 'TokenRevoked'
when GET /user returns 401. This PR completes the user-facing side.

Closes Priyanshu-byte-coder#884
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 3, 2026

@Subhra-Nandi 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:feature GSSoC type bonus: new feature type:security GSSoC type bonus: security (+20 pts) labels Jun 3, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

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

@Priyanshu-byte-coder Priyanshu-byte-coder added gssoc:approved GSSoC: PR approved for scoring level:intermediate GSSoC: Intermediate difficulty (35 pts) labels Jun 3, 2026
@Priyanshu-byte-coder
Copy link
Copy Markdown
Owner

CI is failing because this branch is based on an older version of main that still had @emnapi/core and @emnapi/runtime in the lockfile. Those have since been removed from main.

Please rebase on main:

git fetch origin
git rebase origin/main
git push --force-with-lease

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

Labels

gssoc:approved GSSoC: PR approved for scoring gssoc26 GSSoC 2026 contribution level:intermediate GSSoC: Intermediate difficulty (35 pts) type:feature GSSoC type bonus: new feature type:security GSSoC type bonus: security (+20 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Detect revoked GitHub token and prompt re-authentication gracefully

2 participants