@withkeystone/cli
Version:
Keystone CLI - Test automation for modern web apps
56 lines • 2.17 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.logoutCommand = void 0;
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
const inquirer_1 = __importDefault(require("inquirer"));
const AuthenticatedClient_js_1 = require("../auth/AuthenticatedClient.js");
exports.logoutCommand = new commander_1.Command('logout')
.description('Log out of Keystone CLI')
.option('--api-url <url>', 'API URL', process.env.KEYSTONE_API_URL || 'https://api.withkeystone.com')
.option('-y, --yes', 'Skip confirmation prompt')
.action(async (options) => {
const client = new AuthenticatedClient_js_1.AuthenticatedClient(options.apiUrl);
const isAuthenticated = await client.isAuthenticated();
if (!isAuthenticated) {
console.log(chalk_1.default.yellow('You are not currently logged in.'));
return;
}
// Get session info before logout
let email = 'unknown user';
try {
const session = await client.getSession();
if (session) {
email = session.email;
}
}
catch {
// Ignore errors getting session
}
// Confirm logout unless -y flag is provided
if (!options.yes) {
const { confirm } = await inquirer_1.default.prompt([{
type: 'confirm',
name: 'confirm',
message: `Are you sure you want to log out from ${email}?`,
default: false
}]);
if (!confirm) {
console.log(chalk_1.default.gray('Logout cancelled.'));
return;
}
}
try {
// Perform logout (handles token revocation and clearing)
await client.logout();
console.log(chalk_1.default.green(`✓ Successfully logged out from ${email}.`));
}
catch (error) {
console.error(chalk_1.default.red('✗ Logout failed:'), error instanceof Error ? error.message : error);
process.exit(1);
}
});
//# sourceMappingURL=logout.js.map