UNPKG

scai

Version:

> **AI-powered CLI for local code analysis, commit message suggestions, and natural-language queries.** 100% local, private, GDPR-friendly, made in Denmark/EU with ❤️.

24 lines (23 loc) 1.04 kB
import chalk from 'chalk'; import { Config } from '../config.js'; import { promptForToken } from './token.js'; export async function ensureGitHubAuth() { // First check if the token exists in the config let token = Config.getGitHubToken(); if (token) { console.log("🔐 GitHub token found in config."); return token; // Token already exists in config, return it } // Token doesn't exist in config, prompt the user for it console.log(chalk.red("🔐 GitHub token not found.")); token = await promptForToken(); // Ensure the token is not empty and has the required format (you can extend this check as needed) while (!token || token.trim().length === 0) { console.log("❌ Invalid token entered. Please enter a valid GitHub token."); token = await promptForToken(); } // Save the token in the config Config.setGitHubToken(token.trim()); console.log(chalk.green("✅ GitHub token successfully saved.")); return token.trim(); // Return the trimmed token }