Why GitHub Authentication?
GitHub authentication serves several purposes:Automatic Forking
The system automatically forks the repository to your GitHub account
PR Creation
Creates pull requests on your behalf with your changes
Identity Verification
Ensures contributions are attributed to the correct GitHub user
Seamless Workflow
No need to use Git commands or leave the website
Authentication Flow
Better Auth Configuration
Who To Bother uses better-auth for authentication. The configuration is straightforward and secure:src/lib/auth.ts
Key Features
Stateless Sessions: No database required. All session data is stored in encrypted JWT cookies. OAuth Scopes: The app requests minimal permissions:read:user- Read your public GitHub profileuser:email- Access your email addresspublic_repo- Create and manage forks and PRs in public repositories
Accessing the Session
The application uses better-auth’s client-side hooks to check authentication status:Example Component
Getting the Access Token
When creating a pull request, the server retrieves the GitHub access token from the session:src/app/api/github/create-pr.ts
Security Considerations
How Access Tokens Are Protected
Encrypted Storage: Tokens are encrypted using JWE before being stored in cookies. HTTP-Only Cookies: Session cookies are HTTP-only, preventing access from client-side JavaScript. Secure Flag: Cookies are marked secure in production, ensuring they’re only sent over HTTPS. Short-Lived Sessions: Sessions expire after 7 days of inactivity. Minimal Scopes: The app only requests the minimum permissions needed to function.Token Usage
Access tokens are only used server-side for:- Forking the repository to your GitHub account
- Creating branches in your fork
- Committing changes to company data files
- Opening pull requests to the main repository
Environment Variables
To set up authentication in your own deployment, configure these environment variables:.env
Creating a GitHub OAuth App
Navigate to GitHub Developer Settings
Create a new OAuth App
Click “New OAuth App” and fill in the details:
- Application name: Who To Bother (or your app name)
- Homepage URL:
https://your-domain.com - Authorization callback URL:
https://your-domain.com/api/auth/callback/github
Session Management
Session Lifecycle
Checking Session Status
The session is automatically validated on each request:src/app/api/github/fork.ts
Sign Out
Users can sign out at any time, which clears the session cookie:Example Sign Out
Troubleshooting
”Unauthorized” Error
If you see an unauthorized error:- Try signing out and signing back in
- Check if your session has expired (7 day limit)
- Ensure cookies are enabled in your browser
- Clear your browser cache and try again
”GitHub access token not found”
This error occurs when the access token can’t be retrieved from the session:- Sign out and sign back in to re-authorize
- Check that you granted all requested permissions during OAuth
- Verify the GitHub OAuth app is configured correctly
Session Not Persisting
If you’re repeatedly asked to sign in:- Check if third-party cookies are blocked
- Ensure your browser allows cookies for the domain
- Verify you’re accessing the site over HTTPS in production
For development, ensure
BETTER_AUTH_SECRET is set in your environment. This secret is used to encrypt session data.Using the Dashboard
After signing in, you can access your dashboard at/dashboard. The dashboard provides:
- Session Information: View your current session details and authentication status
- User Profile: See your GitHub profile information
- Quick Links: Navigate to search or back to the homepage
src/app/dashboard.tsx
Sign Out
From the dashboard, you can sign out using the “Sign Out” button, which clears your session and redirects you to the homepage.Login Page
The/login page provides a dedicated sign-in interface. If you attempt to access the contribute pages without being authenticated, you’ll be redirected here. The login page includes:
- GitHub OAuth sign-in button: Initiates the OAuth flow
- Clear messaging: Explains why authentication is needed
- Redirect handling: Returns you to your intended destination after sign-in
Next Steps
Submit Changes
Learn how to submit your first contribution
Contributing Guide
Return to the main contributing guide