fix: detect revoked GitHub token immediately instead of waiting up to 24 hours#2873
Open
Tanisha-sharma7302 wants to merge 2 commits into
Open
Conversation
GSSoC Label Checklist 🏷️@Priyanshu-byte-coder — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2842
Problem
The dashboard only re-validated the stored GitHub OAuth token once every
24 hours (
TOKEN_VALIDATION_INTERVAL_MSinauth.ts). If a user revokedthe app's access in GitHub Settings, the app wouldn't notice until the next
scheduled check — for up to 24 hours. In the meantime, every GitHub API call
silently failed with 401, but the dashboard had no way to tell this apart
from a generic network error, so it just showed stale data or a confusing
error instead of prompting the user to reconnect.
The existing
TokenRevokedBannerindashboard/layout.tsxand thewindow.fetch401-interceptor were already built to show a "reconnect"prompt — but they only fire when
session.error === "TokenRevoked", whichwas only ever set by the slow 24-hour periodic check.
Fix
Added a fast path so a live 401 from GitHub immediately flags the token
as revoked, instead of waiting for the periodic check:
src/lib/token-revocation-flag.ts(new) —markTokenRevokedNow()/wasTokenRevokedNow(), backed by the existing Redis cache with ashort TTL.
src/lib/github-fetch.ts— when any GitHub API call returns a live401, it now calls
markTokenRevokedNow()for that user.src/lib/auth.ts— the NextAuthjwtcallback now checkswasTokenRevokedNow()on every request. If true, it setssession.error = "TokenRevoked"immediately, instead of relying solelyon the 24-hour periodic check.
This means the existing
TokenRevokedBanner("Your GitHub session hasexpired. Please sign out and sign back in to refresh your data.") now
shows up right away on the next page load after revocation, rather than
up to a day later. The original 24-hour periodic check is left in place
as a fallback for routes that don't actively call GitHub.
Testing
pnpm run type-checkpasses with no errors