This guide will help you set up Google and GitHub OAuth authentication for your UPCODE application.
- A Google account for Google OAuth setup
- A GitHub account for GitHub OAuth setup
- Access to your application's environment variables
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Google+ API:
- Go to "APIs & Services" > "Library"
- Search for "Google+ API" and enable it
- Also enable "Google People API"
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth 2.0 Client IDs"
- Configure the OAuth consent screen if prompted:
- User Type: External (for testing) or Internal (for organization use)
- Fill in required fields (App name, User support email, etc.)
- Create OAuth 2.0 Client ID:
- Application type: Web application
- Name: UPCODE (or your preferred name)
- Authorized redirect URIs:
- For development:
http://localhost:3000/api/auth/callback/google - For production:
https://yourdomain.com/api/auth/callback/google
- For development:
- Copy the Client ID and Client Secret
- Add them to your
.env.localfile:GOOGLE_CLIENT_ID=your-google-client-id-here GOOGLE_CLIENT_SECRET=your-google-client-secret-here
- Go to GitHub Developer Settings
- Click "New OAuth App"
- Fill in the application details:
- Application name: UPCODE
- Homepage URL:
- Development:
http://localhost:3000 - Production:
https://yourdomain.com
- Development:
- Authorization callback URL:
- Development:
http://localhost:3000/api/auth/callback/github - Production:
https://yourdomain.com/api/auth/callback/github
- Development:
- After creating the app, copy the Client ID
- Generate a Client Secret and copy it
- Add them to your
.env.localfile:GITHUB_ID=your-github-client-id-here GITHUB_SECRET=your-github-client-secret-here
Add a strong secret for NextAuth:
NEXTAUTH_SECRET=your-strong-secret-key-here
NEXTAUTH_URL=http://localhost:3000To generate a secure secret, you can use:
openssl rand -base64 32Your .env.local file should look like this:
# MongoDB Configuration
MONGODB_URI=mongodb://localhost:27017/upcode
# NextAuth Configuration
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-generated-secret-here
# Google OAuth
GOOGLE_CLIENT_ID=your-google-client-id-here
GOOGLE_CLIENT_SECRET=your-google-client-secret-here
# GitHub OAuth
GITHUB_ID=your-github-client-id-here
GITHUB_SECRET=your-github-client-secret-here
# Other configurations...- Restart your development server:
npm run dev - Go to the login page
- Try signing in with Google and GitHub
- Check the console for any error messages
- "Configuration Error": Check that all required environment variables are set
- "Redirect URI Mismatch": Ensure the callback URLs match exactly
- "Invalid Client": Double-check your Client ID and Secret
- "Consent Screen Error": Make sure your OAuth consent screen is properly configured
- For development, use
http://localhost:3000URLs - For production, replace with your actual domain and use
https:// - Update both the OAuth app settings and your environment variables
- Never commit your
.env.localfile to version control - Use different OAuth apps for development and production
- Regularly rotate your secrets
- Use strong, unique secrets for NEXTAUTH_SECRET
If you encounter issues:
- Check the NextAuth.js documentation: https://next-auth.js.org/
- Verify your OAuth app configurations
- Check the browser console and server logs for detailed error messages