This document explains how to set up the GitHub-integrated content submission system for PrepGuides.dev.
- GitHub OAuth Authentication: Users must log in with GitHub to submit content
- Automated PR Creation: Content submissions automatically create pull requests
- Form-based Interface: User-friendly form for content submission
- Preview System: Users can preview their content before submission
- Quality Control: All submissions go through PR review process
- Go to GitHub Settings → Developer settings → OAuth Apps
- Click "New OAuth App"
- Fill in the details:
- Application name: PrepGuides.dev Content Submission
- Homepage URL:
https://prepguides-dev.vercel.app - Authorization callback URL:
https://prepguides-dev.vercel.app/auth/callback
- Note down the Client ID and generate a Client Secret
Important: For development and preview deployments, you'll need to add additional callback URLs:
http://localhost:3000/auth/callback(for local development)https://*.vercel.app/auth/callback(for all Vercel preview deployments)
Note: GitHub doesn't support wildcard domains in OAuth callback URLs. For preview deployments, you have two options:
- Add each preview URL manually (not practical for frequent PRs)
- Use a proxy service or configure multiple specific URLs
- Test primarily on production domain and use preview for development only
Create a .env file in the project root with:
GITHUB_CLIENT_ID=your_github_client_id_here
GITHUB_CLIENT_SECRET=your_github_client_secret_here- Install Vercel CLI:
npm install -g vercel - Set environment variables in Vercel:
vercel env add GITHUB_CLIENT_ID vercel env add GITHUB_CLIENT_SECRET
- Deploy:
vercel --prod
Ensure the GitHub OAuth app has the following scopes:
repo- Full control of private repositoriesuser:email- Access to user email addresses
- User clicks "Login with GitHub"
- Redirected to GitHub OAuth
- User authorizes the application
- GitHub redirects back with authorization code
- Server exchanges code for access token
- User is authenticated and can submit content
- Authenticated user fills out the content form
- User previews their content
- User confirms submission
- System creates a new branch in the repository
- Content file is created in the appropriate category folder
- Pull request is created with proper labels
- User receives confirmation with PR link
Submitted content is organized as follows:
{category}/
{sanitized-title}.html
Example:
algorithms/
advanced-sorting-algorithms.html
kubernetes/
pod-lifecycle-management.html
Exchanges OAuth code for access token.
Request:
{
"code": "github_oauth_code"
}Response:
{
"access_token": "gho_...",
"token_type": "bearer",
"scope": "repo,user:email"
}Creates a pull request for content submission.
Request:
{
"title": "Content Submission: Advanced Sorting",
"body": "PR description...",
"head": "username:branch-name",
"base": "main"
}Response:
{
"number": 123,
"html_url": "https://github.com/prepguides/prepguides.dev/pull/123",
"title": "Content Submission: Advanced Sorting",
"state": "open",
"created_at": "2024-01-01T00:00:00Z"
}- OAuth Scopes: Only request necessary scopes
- Token Storage: Access tokens are stored in localStorage (client-side)
- HTTPS Only: All authentication must happen over HTTPS
- State Parameter: OAuth flow includes state parameter for CSRF protection
- Input Validation: All form inputs are validated before submission
-
"Invalid redirect URI"
- Ensure callback URL in GitHub OAuth app matches exactly
- Check for trailing slashes or protocol mismatches
-
"Insufficient permissions"
- Verify OAuth app has correct scopes
- Check if user has access to the target repository
-
"Failed to create PR"
- Ensure user has write access to the repository
- Check if branch name conflicts exist
Enable debug logging by adding to the browser console:
localStorage.setItem('debug', 'true');When contributing to this system:
- Test the OAuth flow thoroughly
- Ensure all error cases are handled gracefully
- Validate all user inputs
- Test with different GitHub user permissions
- Verify PR creation works correctly
- GitHub App integration for better permissions
- Content templates and validation
- Automated content formatting
- Integration with CI/CD for content validation
- User dashboard for tracking submissions
- Content approval workflow