-
File:
src/lib/auth.ts- Updated GitHub OAuth scopes to
repo read:org(matching PRD) - JWT callback stores access token
- Session callback extends session with user data
- Updated GitHub OAuth scopes to
-
File:
src/app/api/auth/[...nextauth]/route.ts- Already existed, exports NextAuth handlers
-
File:
src/app/api/github/validate/route.ts✨ NEW- POST endpoint to validate Personal Access Tokens
- Checks token validity with GitHub API
- Returns user data and scopes
-
File:
src/app/api/auth/pat/route.ts- Already existed with full PAT support (POST, GET, DELETE)
- Stores PAT in HTTP-only cookies
- Validates scopes
- File:
src/lib/github-api.ts✨ NEW (486 lines)- Complete GitHubAPI class with Octokit + GraphQL
- Rate limiting with retry logic and exponential backoff
- All 5 GraphQL queries from migration guide:
validateToken()- Validate token and get usergetOrganizations()- Get user's orgs + personal accountgetRepositories()- Get repos (personal or org)getPullRequests()- Get PRs with paginationgetPullRequestsWithDetails()- Get PRs with reviews, comments, commits
- Methods:
query()- GraphQL query with rate limitingvalidateToken()getOrganizations()getRepositories(orgLogin, isPersonal)getPullRequests(orgLogin, daysAgo, isPersonal)getPullRequestsForRepos(repoNames, daysAgo)getPullRequestsWithDetails(repoNames, daysAgo)- Private helpers:
sleep(),getPullRequestsForSingleRepo(),getPullRequestsWithDetailsForSingleRepo()
-
File:
src/lib/hooks/useGitHubAuth.ts✨ NEW- Dual authentication support (OAuth + PAT)
- Checks NextAuth session first, falls back to localStorage PAT
- Methods:
authenticate(),logout(),validatePAT() - Returns:
user,token,isAuthenticated,loading,error
-
File:
src/lib/hooks/useGitHubData.ts✨ NEW- Data fetching hook using GitHubAPI client
- Initializes API when token changes
- Method:
fetchPullRequests(repoNames, daysAgo, useDetailedAnalysis) - Returns:
pullRequests,loading,error,api
-
File:
src/components/auth/AuthProvider.tsx✨ NEW- SessionProvider wrapper for NextAuth
-
File:
src/components/auth/AuthForm.tsx✨ NEW- Beautiful dual-auth UI (OAuth + PAT)
- Marketing section with privacy messaging
- Token creation instructions
- Error handling
-
File:
src/app/login/page.tsx- Already existed with excellent UX
- Integrates with both OAuth and PAT flows
-
File:
src/providers/index.tsx- Already has SessionProvider configured
next-auth@5.0.0-beta.30- Already installed@octokit/rest@22.0.1- Already installed@octokit/graphql- ✨ Newly installed
- File:
.env.local- Updated with proper structureGITHUB_CLIENT_ID- Needs configurationGITHUB_CLIENT_SECRET- Needs configurationNEXTAUTH_SECRET- Needs configurationNEXTAUTH_URL- Set to http://localhost:3000NODE_ENV- Set to development
- Go to https://github.com/settings/developers
- Click "New OAuth App"
- Fill in:
- Application name: Repo Wrapped (or your choice)
- Homepage URL:
http://localhost:3000 - Authorization callback URL:
http://localhost:3000/api/auth/callback/github
- Click "Register application"
- Copy the Client ID
- Click "Generate a new client secret" and copy it
Run this command:
openssl rand -base64 32Replace the placeholder values in .env.local:
GITHUB_CLIENT_ID=your_actual_client_id_here
GITHUB_CLIENT_SECRET=your_actual_client_secret_here
NEXTAUTH_SECRET=your_generated_secret_here# Stop the current server (Ctrl+C)
npm run dev- Go to http://localhost:3000/login
- Click "Continue with GitHub"
- Authorize the app on GitHub
- Should redirect back to home page authenticated
- Go to http://localhost:3000/login
- Click "Use Personal Access Token"
- Create a token at https://github.com/settings/tokens/new?scopes=repo,read:org
- Paste the token and click "Connect"
- Should authenticate and redirect to home page
Use the hooks in any component:
import { useGitHubAuth } from '@/lib/hooks/useGitHubAuth';
import { useGitHubData } from '@/lib/hooks/useGitHubData';
function MyComponent() {
const { user, token, isAuthenticated } = useGitHubAuth();
const { api, fetchPullRequests } = useGitHubData();
// Fetch organizations
const orgs = await api?.getOrganizations();
// Fetch repositories
const repos = await api?.getRepositories('myorg', false);
// Fetch pull requests
const prs = await fetchPullRequests(['owner/repo'], 60, true);
}- NextAuth.js configured with GitHub OAuth
- PAT validation endpoint created
- GitHub API client with all GraphQL queries
- Rate limiting and retry logic implemented
- React hooks for auth and data fetching
- UI components for authentication
- Dual storage (NextAuth session + localStorage)
- TypeScript types for all responses
- No TypeScript errors
- OAuth flow end-to-end (needs GitHub OAuth app setup)
- PAT flow end-to-end (needs valid PAT)
- GitHub API calls (needs authentication)
- Rate limiting behavior
- Error handling
User Authentication Flow:
1. User visits /login
2. Chooses OAuth or PAT
3. OAuth: Redirects to GitHub → Returns with token → Stored in NextAuth session
4. PAT: Validates via /api/github/validate → Stored in localStorage
5. useGitHubAuth hook checks both sources
6. GitHubAPI client initialized with token
7. useGitHubData hook provides data fetching methods
- Configure OAuth App - Set up GitHub OAuth credentials
- Update .env.local - Add real credentials
- Test Authentication - Try both OAuth and PAT flows
- Integrate with App - Use hooks in your wrapped components
- Test API Calls - Verify GitHub API client works
- Handle Edge Cases - Test rate limiting, errors, logout
Implementation Time: ~2 hours Status: ✅ Complete - Ready for configuration and testing