UNPKG

hackages

Version:

CLI tool for learning software development concepts through test-driven development

28 lines (27 loc) 1.03 kB
import { loginWithGitHub, isLoggedIn, getCurrentUser, clearAuth, } from "../services/auth.js"; import { printInfo, printSuccess, printWarning, printError, } from "../utils/console.js"; export async function loginCommand() { try { // Check if already logged in if (isLoggedIn()) { const user = getCurrentUser(); printWarning(`⚠️ You are already logged in as ${user?.name || user?.login}.`); printInfo("Run 'hackages logout' if you want to switch accounts."); return; } await loginWithGitHub(); } catch (error) { printError(`❌ Login failed: ${error}`); printInfo("Please try again or check your internet connection."); } } export async function logoutCommand() { if (!isLoggedIn()) { printWarning("⚠️ You are not currently logged in."); return; } const user = getCurrentUser(); clearAuth(); printSuccess(`✅ Successfully logged out from ${user?.name || user?.login}.`); }