UNPKG

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
# ๐Ÿš€ 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! [![npm version](https://badge.fury.io/js/%40cipherai%2Fauth-setup.svg)](https://badge.fury.io/js/%40cipherai%2Fauth-setup) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](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 ![GitHub stars](https://img.shields.io/github/stars/cipherai/auth-setup?style=social) ![GitHub forks](https://img.shields.io/github/forks/cipherai/auth-setup?style=social) ![GitHub issues](https://img.shields.io/github/issues/cipherai/auth-setup) ![GitHub pull requests](https://img.shields.io/github/issues-pr/cipherai/auth-setup) --- Made with โค๏ธ by [CipherAI](https://github.com/cipherai) for the developer community