Overview
The GitHub OAuth module integrates GitHub authentication into your existing Node.js Express application using Passport.js. The module automatically:- Installs all required dependencies
- Generates configuration and route files
- Patches your main app file intelligently
- Injects environment variables to
.env - Supports both JavaScript and TypeScript
Installation
Run the following command in your project directory:Interactive Setup
The CLI will guide you through an interactive setup process with the following prompts:Specify Entry File
Enter your project’s main entry file (relative to root)
For TypeScript projects, if the file doesn’t exist, Devark will auto-detect
.ts files in your src/ directory.Dependencies Installed
The module automatically installs the following packages:Runtime Dependencies
TypeScript Dev Dependencies (TypeScript only)
Generated File Structure
- JavaScript
- TypeScript
Configuration
The following environment variables are automatically added to your.env file:
Your GitHub OAuth App Client ID from GitHub Developer Settings
Your GitHub OAuth App Client Secret from GitHub Developer Settings
The callback URL where GitHub redirects after authentication
Secret key used to sign the session ID cookie
Example .env
Generated Code
Strategy Configuration
- JavaScript
- TypeScript
The module generates
config/githubStrategy.js:Authentication Routes
- JavaScript
- TypeScript
The module generates
routes/githubAuthRoutes.js:Usage Example
After installation, your app will automatically have GitHub OAuth configured. To test:Available Routes
GET /auth/github- Initiates GitHub OAuth flow (requestsuser:emailscope)GET /auth/github/callback- Handles GitHub’s redirect after authenticationGET /auth/github/success- Success page after authentication
App.js Patching
The module intelligently patches your main app file to include:- Required imports for passport and session management
- Session middleware configuration (placed before passport initialization)
- Passport initialization middleware
- Route registration for GitHub OAuth routes
The patching logic ensures no duplicate imports or middleware declarations. It detects existing setup and only adds what’s missing.
Troubleshooting
Error: Entry file not found
Error: Entry file not found
Solution: Ensure your
app.js or src/app.ts file exists before running the module installation. Create the file if it doesn’t exist:Error: Redirect URI mismatch
Error: Redirect URI mismatch
Solution: Ensure the callback URL in your GitHub OAuth App settings matches the
GITHUB_CALLBACK_URL in your .env file.- Go to GitHub Developer Settings
- Select your OAuth App
- Update the Authorization callback URL to match your
.envvalue - Typically:
http://localhost:3000/auth/github/callback
Session is not persisting
Session is not persisting
Solution: Ensure you have a strong
SESSION_SECRET in your .env file and that express-session is configured before passport initialization.The module handles this automatically, but if you’re manually configuring, ensure this order:TypeScript errors after installation
TypeScript errors after installation
Solution: The module installs TypeScript types automatically. If you still see errors:
Cannot find module errors
Cannot find module errors
Solution: If dependencies weren’t installed properly, manually install them:
Getting GitHub OAuth Credentials
Navigate to Developer Settings
Visit GitHub Developer Settings and sign in to your GitHub account.
Fill Application Details
- Application name: Your app name
- Homepage URL:
http://localhost:3000 - Authorization callback URL:
http://localhost:3000/auth/github/callback
Customizing User Data
By default, the strategy returns the entire GitHub profile. To customize what user data you store:Accessing User Data in Routes
After authentication, user data is available inreq.user:
Next Steps
Google OAuth
Add Google authentication to your project
Resend OTP
Add email OTP verification

