google-oauth-cli-generator
Version:
CLI tool to quickly set up Google OAuth authentication for hackathons and projects
288 lines (212 loc) โข 7.8 kB
Markdown
# ๐ CipherAI Auth Setup CLI
A powerful CLI tool to quickly set up Google OAuth authentication for hackathons and projects. Generate complete authentication boilerplates in seconds!
[](https://badge.fury.io/js/%40cipherai%2Fauth-setup)
[](https://opensource.org/licenses/MIT)
## โจ Features
- ๐ **Complete Google OAuth Setup** - Full authentication flow with Passport.js
- โก **Multiple Frontend Frameworks** - React, Next.js, or Vanilla JavaScript
- ๐ **Backend Options** - Express.js or Fastify
- ๐พ **Database Support** - MongoDB, PostgreSQL, or in-memory storage
- ๐จ **Beautiful UI** - Pre-styled login components with modern design
- ๐ฆ **Zero Configuration** - Just run and answer prompts
- ๐งช **Test Ready** - Includes comprehensive test suites
- ๐ **Documentation** - Complete setup guides and examples
## ๐ Quick Start
### Installation
```bash
# Install globally
npm install -g @cipherai/auth-setup
# Or use npx (recommended)
npx @cipherai/auth-setup setup
```
### Usage
```bash
# Initialize new authentication project
cipherai-auth setup
# Or using npx
npx @cipherai/auth-setup setup
```
## ๐ Prerequisites
Before running the CLI, you'll need:
1. **Google Cloud Console Project**
- Go to [Google Cloud Console](https://console.cloud.google.com/)
- Create a new project or select existing one
- Enable Google+ API
2. **OAuth 2.0 Credentials**
- Navigate to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Choose "Web Application"
- Add your redirect URI (e.g., `http://localhost:3000/auth/google/callback`)
## ๐ฏ What You'll Get
The CLI will ask you a few questions and generate a complete project structure:
### ๐ Questions Asked
1. **Google OAuth Client ID** - Your Google OAuth client ID
2. **Google OAuth Client Secret** - Your Google OAuth client secret
3. **Redirect URI** - OAuth callback URL (default: `http://localhost:3000/auth/google/callback`)
4. **Frontend Framework** - React, Next.js, or Vanilla JavaScript
5. **Backend Framework** - Express.js or Fastify
6. **Database** - MongoDB, PostgreSQL, or none (in-memory)
7. **Project Name** - Name for your project folder
### ๐ Generated Structure
```
your-project/
โโโ frontend/ # Frontend application
โ โโโ src/
โ โ โโโ components/ # Login/Profile components
โ โ โโโ App.tsx # Main application
โ โ โโโ ...
โ โโโ package.json
โ โโโ ...
โโโ backend/ # Backend API server
โ โโโ src/
โ โ โโโ routes/ # Authentication routes
โ โ โโโ config/ # Passport & database config
โ โ โโโ models/ # User models (if database selected)
โ โ โโโ index.ts # Server entry point
โ โโโ package.json
โ โโโ ...
โโโ .env.example # Environment variables template
โโโ .gitignore # Git ignore rules
โโโ README.md # Project documentation
```
## ๐ Supported Tech Stacks
### Frontend Options
- **React** - Modern React with TypeScript, Vite, and styled components
- **Next.js** - Next.js 14 with App Router and TypeScript
- **Vanilla JS** - Pure JavaScript with modern ES6+ features
### Backend Options
- **Express.js** - Popular Node.js framework with Passport.js
- **Fastify** - High-performance alternative to Express
### Database Options
- **MongoDB** - NoSQL database with Mongoose ODM
- **PostgreSQL** - Relational database with native pg driver
- **None** - In-memory storage for quick prototypes
## ๐ Getting Started (After Generation)
1. **Navigate to your project**
```bash
cd your-project-name
```
2. **Set up environment variables**
```bash
cp .env.example .env
# Edit .env with your actual values
```
3. **Install dependencies**
```bash
# Frontend
cd frontend && npm install
# Backend
cd ../backend && npm install
```
4. **Start development servers**
```bash
# Terminal 1 - Backend
cd backend && npm run dev
# Terminal 2 - Frontend
cd frontend && npm run dev
```
5. **Open your browser**
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
## ๐ง Environment Variables
### Required Variables
```bash
# Google OAuth Configuration
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-client-secret
REDIRECT_URI=http://localhost:3000/auth/google/callback
# Session Configuration
SESSION_SECRET=your-session-secret-change-in-production
# Database Configuration (if using database)
MONGODB_URI=mongodb://localhost:27017/your-app
# OR
DATABASE_URL=postgresql://username:password@localhost:5432/your_app
# Application Configuration
PORT=5000
NODE_ENV=development
FRONTEND_URL=http://localhost:3000
```
## ๐ API Reference
### Authentication Endpoints
- `GET /api/auth/google` - Initiate Google OAuth flow
- `GET /api/auth/google/callback` - OAuth callback handler
- `GET /api/auth/user` - Get current authenticated user
- `POST /api/auth/logout` - Logout user
### Health Check
- `GET /api/health` - Server health status
## ๐งช Testing
The generated project includes comprehensive test suites:
```bash
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watch
```
## ๐ Deployment
### Frontend Deployment
**Vercel (Recommended for Next.js)**
```bash
npm install -g vercel
vercel
```
**Netlify (Great for React/Vanilla)**
```bash
npm run build
# Upload dist/ folder to Netlify
```
### Backend Deployment
**Railway**
```bash
npm install -g @railway/cli
railway login
railway init
railway up
```
**Heroku**
```bash
heroku create your-app-name
git push heroku main
```
### Environment Variables in Production
Remember to set these in your deployment platform:
- `GOOGLE_CLIENT_ID`
- `GOOGLE_CLIENT_SECRET`
- `REDIRECT_URI` (update to production URL)
- `SESSION_SECRET` (generate a secure random string)
- Database connection strings
- `NODE_ENV=production`
## ๐ค Contributing
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
### Development Setup
```bash
# Clone the repository
git clone https://github.com/cipherai/auth-setup.git
cd auth-setup
# Install dependencies
npm install
# Run in development mode
npm run dev
# Run tests
npm test
# Build for production
npm run build
```
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## ๐ Issues & Support
- ๐ [Report a Bug](https://github.com/cipherai/auth-setup/issues/new?template=bug_report.md)
- ๐ก [Request a Feature](https://github.com/cipherai/auth-setup/issues/new?template=feature_request.md)
- ๐ฌ [General Discussion](https://github.com/cipherai/auth-setup/discussions)
## ๐ Acknowledgments
- [Passport.js](http://www.passportjs.org/) - Simple, unobtrusive authentication
- [Google OAuth 2.0](https://developers.google.com/identity/protocols/oauth2) - Secure authentication
- [Inquirer.js](https://github.com/SBoudrias/Inquirer.js/) - Beautiful command line interfaces
## ๐ Stats




---
Made with โค๏ธ by [CipherAI](https://github.com/cipherai) for the developer community