google-oauth-cli-generator
Version:
CLI tool to quickly set up Google OAuth authentication for hackathons and projects
141 lines ⢠5.72 kB
JavaScript
;
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