UNPKG

@withkeystone/cli

Version:

Keystone CLI - Test automation for modern web apps

61 lines 2.97 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.authStatusCommand = void 0; const commander_1 = require("commander"); const chalk_1 = __importDefault(require("chalk")); const AuthenticatedClient_js_1 = require("../auth/AuthenticatedClient.js"); exports.authStatusCommand = new commander_1.Command('auth-status') .description('Check authentication status') .alias('whoami') .option('--api-url <url>', 'API URL', process.env.KEYSTONE_API_URL || 'https://api.withkeystone.com') .action(async (options) => { const client = new AuthenticatedClient_js_1.AuthenticatedClient(options.apiUrl); try { const isAuthenticated = await client.isAuthenticated(); if (!isAuthenticated) { console.log(chalk_1.default.yellow('Not authenticated')); console.log(chalk_1.default.gray('\nRun "keystone init" to authenticate')); process.exit(1); } // Get session info const session = await client.getSession(); if (!session) { console.log(chalk_1.default.yellow('Authenticated but unable to retrieve session information')); process.exit(1); } console.log(chalk_1.default.green('✓ Authenticated\n')); console.log(chalk_1.default.bold('User:'), session.email); console.log(chalk_1.default.bold('User ID:'), session.user_id); console.log(chalk_1.default.bold('Organization:'), session.organization_name || 'No organization'); console.log(chalk_1.default.bold('Organization ID:'), session.organization_id || 'N/A'); console.log(chalk_1.default.bold('Scopes:'), session.scopes?.join(', ') || 'N/A'); // Parse expiry time if (session.expires_at) { const expiresAt = new Date(session.expires_at); const now = new Date(); const diffMs = expiresAt.getTime() - now.getTime(); if (diffMs > 0) { const diffMins = Math.floor(diffMs / 60000); const diffHours = Math.floor(diffMins / 60); const remainingMins = diffMins % 60; if (diffHours > 0) { console.log(chalk_1.default.bold('Token expires in:'), `${diffHours}h ${remainingMins}m`); } else { console.log(chalk_1.default.bold('Token expires in:'), `${remainingMins}m`); } } else { console.log(chalk_1.default.bold('Token expires in:'), chalk_1.default.red('Expired')); } } } catch (error) { console.error(chalk_1.default.red('✗ Failed to check authentication status:'), error instanceof Error ? error.message : error); process.exit(1); } }); //# sourceMappingURL=auth-status.js.map