cloakx
Version:
Cloakx is a secure, lightweight CLI tool to manage your development secrets locally — no cloud, no hassle. Store, retrieve, and manage secrets across projects with encryption and ease. 🔐 Perfect for solo devs, indie hackers, and teams who value speed, si
50 lines (49 loc) • 2.04 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loginCommand = loginCommand;
// commands/login.ts
const commander_1 = require("commander");
const inquirer_1 = __importDefault(require("inquirer"));
const fs_1 = __importDefault(require("fs"));
const paths_1 = require("../config/paths");
const crypto_1 = require("../utils/crypto");
const path_1 = __importDefault(require("path")); // Add this
function loginCommand() {
const cmd = new commander_1.Command('login');
cmd.action(async () => {
const { password } = await inquirer_1.default.prompt([
{
type: 'password',
name: 'password',
message: 'Enter your vault password:',
},
]);
// If vault exists, try to validate password
if (fs_1.default.existsSync(paths_1.vaultPath)) {
try {
const vault = JSON.parse(fs_1.default.readFileSync(paths_1.vaultPath, 'utf-8'));
const testKey = Object.keys(vault)[0];
if (testKey) {
(0, crypto_1.decrypt)(vault[testKey], password); // If this fails, catch will run
}
}
catch (err) {
console.log('❌ Incorrect password. Login failed.');
return;
}
}
const session = {
token: Buffer.from(`${Date.now()}`).toString('base64'),
createdAt: new Date().toISOString(),
createdAtTimestamp: Date.now(),
};
fs_1.default.mkdirSync(path_1.default.dirname(paths_1.sessionPath), { recursive: true });
// fs.mkdirSync(sessionPath.replace('/session.json', ''), { recursive: true });
fs_1.default.writeFileSync(paths_1.sessionPath, JSON.stringify({ ...session, password }));
console.log('🔐 Logged in');
});
return cmd;
}