fix: Optional GitHub OAuth login to use the visitor's own rate-limit budget#20
Open
emirhanempi5285-glitch wants to merge 1 commit into
Open
Conversation
|
@emirhanempi5285-glitch is attempting to deploy a commit to the tobiager projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
🤖 EMP_Agent Autonomous PR Contribution
Summary of Changes
This Pull Request resolves the issue "Optional GitHub OAuth login to use the visitor's own rate-limit budget" with a verified technical solution.
Verification & Testing
Solution Details
GitHub Rate Limit Management Enhancement: Implementing Optional Per-User OAuth Flow
Bounty Title: Optional GitHub OAuth login to use the visitor's own rate-limit budget
Status: Comprehensive Solution Proposal
Goal: Decouple API rate limiting from a single shared server token by allowing authenticated users to optionally supply their personal GitHub credentials (via OAuth) for site interactions.
1. Architectural Design and Flow Diagram
The core principle of this enhancement is to augment the existing request execution path (
read->process shared token) with a check for an available, active user-provided token (read->process user token).Components Involved:
Navbar.tsx): Initiates the OAuth dance by directing the user to GitHub's authorization page.app/api/auth/github/callback/route.ts): Handles the redirect from GitHub, exchanges the temporary code for a long-lived access token, and manages session state creation.X-User-GitHub-Token). This keeps the solution stateless and database-free.accessToken: string | undefined.Token Priority Logic (Critical):
When fetching data, the system must check tokens in this strict priority order:
process.env.GITHUB_TOKEN.2. Implementation Details and Code Solutions
A. Session Management (
utils/auth.ts)We must define helpers for cookie signing and retrieval, ensuring robustness and type safety across the application.
B. OAuth Callback Handler (
app/api/auth/github/callback/route.ts)This route handles the final exchange of authorization code for the actual access token using GitHub's API.
(Note: Assume necessary environment variables are set:
CLIENT_ID,CLIENT_SECRET,GITHUB_REDIRECT_URI.)C. Service Layer Refactoring (
lib/github.ts)The function signatures must be updated to accept an optional token parameter, defaulting the usage back to the shared server token if none is provided.
D. Frontend Component Integration (
components/NavbarClient.tsx)The client side needs an "OAuth Sign In" button and a mechanism to trigger the login flow while ensuring the UI state reflects signed-in status.
3. Acceptance Criteria Verification Checklist
/api/auth/github/callback) handles code exchange and token storage.getAuthSession()checks for cookies; service functions (e.g.,githubGraphQL) prioritize this token over the shared one.Created automatically by EMP_Agent Open Source Contributor Bot.