UNPKG

google-oauth-cli-generator

Version:

CLI tool to quickly set up Google OAuth authentication for hackathons and projects

141 lines • 5.72 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.setupAuth = setupAuth; const inquirer_1 = __importDefault(require("inquirer")); const chalk_1 = __importDefault(require("chalk")); const ora_1 = __importDefault(require("ora")); const project_generator_1 = require("../generators/project-generator"); const validation_1 = require("../utils/validation"); async function setupAuth() { console.log(chalk_1.default.cyan.bold('\nšŸš€ Welcome to CipherAI Google Auth CLI\n')); console.log(chalk_1.default.yellow('šŸ“‹ Before we start, make sure you have:')); console.log(chalk_1.default.gray('1. Google Cloud Console project created')); console.log(chalk_1.default.gray('2. OAuth 2.0 Client ID and Secret ready')); console.log(chalk_1.default.gray('3. Go to: https://console.cloud.google.com/apis/credentials\n')); const config = await promptForConfig(); const spinner = (0, ora_1.default)('Setting up your authentication system...').start(); try { await (0, project_generator_1.generateProject)(config); spinner.succeed(chalk_1.default.green('āœ… Authentication system set up successfully!')); console.log(chalk_1.default.cyan('\nšŸŽ‰ Your Google OAuth login is ready!')); console.log(chalk_1.default.gray(`šŸ“ Project created in: ./${config.projectName}`)); console.log(chalk_1.default.gray('\nšŸ“– Next steps:')); console.log(chalk_1.default.white(` cd ${config.projectName}`)); console.log(chalk_1.default.white(' npm install')); console.log(chalk_1.default.white(' npm run dev')); } catch (error) { spinner.fail(chalk_1.default.red('āŒ Failed to set up authentication system')); console.error(chalk_1.default.red('Error:', error instanceof Error ? error.message : 'Unknown error')); process.exit(1); } } async function promptForConfig() { const answers = await inquirer_1.default.prompt([ { type: 'input', name: 'clientId', message: 'šŸ”‘ What is your Google OAuth Client ID?', validate: (input) => { if (!input.trim()) return 'Client ID is required'; if (!input.includes('.apps.googleusercontent.com')) { return 'Client ID should end with .apps.googleusercontent.com'; } return true; } }, { type: 'password', name: 'clientSecret', message: 'šŸ” What is your Google OAuth Client Secret?', validate: (input) => { if (!input.trim()) return 'Client Secret is required'; if (input.length < 20) return 'Client Secret seems too short'; return true; } }, { type: 'input', name: 'redirectUri', message: 'šŸ”„ What is your Redirect URI?', default: 'http://localhost:3000/auth/google/callback', validate: (input) => { if (!input.trim()) return 'Redirect URI is required'; if (!(0, validation_1.isValidUrl)(input)) { return 'Please enter a valid URL'; } return true; } }, { type: 'list', name: 'frontend', message: 'āš›ļø What frontend framework do you use?', choices: [ { name: 'React', value: 'react' }, { name: 'Next.js', value: 'next' }, { name: 'Vanilla JavaScript', value: 'vanilla' } ], default: 'react' }, { type: 'list', name: 'backend', message: 'šŸš€ What backend framework do you prefer?', choices: [ { name: 'Express.js', value: 'express' }, { name: 'Fastify', value: 'fastify' } ], default: 'express' }, { type: 'confirm', name: 'useDatabase', message: 'šŸ’¾ Do you want to store user data in a database?', default: true }, { type: 'list', name: 'database', message: 'šŸ—„ļø Which database do you want to use?', choices: [ { name: 'MongoDB', value: 'mongodb' }, { name: 'PostgreSQL', value: 'postgresql' }, { name: 'None (memory only)', value: 'none' } ], when: (answers) => answers.useDatabase, default: 'mongodb' }, { type: 'input', name: 'projectName', message: 'šŸ“ What should be the name of the project folder?', default: 'auth-boilerplate', validate: (input) => { if (!input.trim()) return 'Project name is required'; if (!/^[a-zA-Z0-9-_]+$/.test(input)) { return 'Project name can only contain letters, numbers, hyphens, and underscores'; } return true; } } ]); return { clientId: answers.clientId, clientSecret: answers.clientSecret, redirectUri: answers.redirectUri, frontend: answers.frontend, backend: answers.backend, database: answers.database || 'none', projectName: answers.projectName }; } //# sourceMappingURL=setup.js.map