@vibe-assurance/cli 1.7.1 → 1.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/env.js +14 -3
- package/src/commands/login.js +4 -2
package/package.json
CHANGED
package/src/commands/env.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
const chalk = require('chalk');
|
|
10
10
|
const ora = require('ora');
|
|
11
|
-
const { getEnvironment, setEnvironment, isAdmin, hasValidCredentials } = require('../config/credentials');
|
|
11
|
+
const { getEnvironment, setEnvironment, isAdmin, hasValidCredentials, deleteCredentials } = require('../config/credentials');
|
|
12
12
|
const {
|
|
13
13
|
ENVIRONMENTS,
|
|
14
14
|
getEnvironmentConfig,
|
|
@@ -91,10 +91,12 @@ async function listEnvironments() {
|
|
|
91
91
|
/**
|
|
92
92
|
* CR-2026-061: Switch to a specific environment
|
|
93
93
|
* Internal environments require admin role
|
|
94
|
+
* Switching environments clears credentials and requires re-login
|
|
94
95
|
* @param {string} envName - Environment name (prod, dev, local)
|
|
95
96
|
*/
|
|
96
97
|
async function switchEnvironment(envName) {
|
|
97
98
|
const config = getEnvironmentConfig(envName);
|
|
99
|
+
const currentEnv = await getEnvironment();
|
|
98
100
|
|
|
99
101
|
if (!config) {
|
|
100
102
|
console.error(chalk.red(`Unknown environment: ${envName}`));
|
|
@@ -102,6 +104,12 @@ async function switchEnvironment(envName) {
|
|
|
102
104
|
process.exit(1);
|
|
103
105
|
}
|
|
104
106
|
|
|
107
|
+
// Already on this environment?
|
|
108
|
+
if (envName === currentEnv) {
|
|
109
|
+
console.log(chalk.yellow(`Already using ${config.name} environment.`));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
105
113
|
// Check if internal environment - require admin
|
|
106
114
|
if (isInternalOnly(envName)) {
|
|
107
115
|
// Must be logged in first
|
|
@@ -125,6 +133,10 @@ async function switchEnvironment(envName) {
|
|
|
125
133
|
const spinner = ora(`Switching to ${config.name}...`).start();
|
|
126
134
|
|
|
127
135
|
try {
|
|
136
|
+
// Clear existing credentials - different environments have different auth
|
|
137
|
+
await deleteCredentials();
|
|
138
|
+
|
|
139
|
+
// Store only the new environment (no auth tokens)
|
|
128
140
|
await setEnvironment(envName);
|
|
129
141
|
spinner.succeed(`Switched to ${chalk.bold(config.name)}`);
|
|
130
142
|
|
|
@@ -134,11 +146,10 @@ async function switchEnvironment(envName) {
|
|
|
134
146
|
if (config.internal) {
|
|
135
147
|
console.log('');
|
|
136
148
|
console.log(chalk.yellow('⚠ You are now using an internal environment.'));
|
|
137
|
-
console.log(chalk.dim(' Run `vibe env prod` to switch back to production.'));
|
|
138
149
|
}
|
|
139
150
|
|
|
140
151
|
console.log('');
|
|
141
|
-
console.log(chalk.
|
|
152
|
+
console.log(chalk.cyan('You have been logged out. Run `vibe login` to authenticate with this environment.'));
|
|
142
153
|
console.log('');
|
|
143
154
|
} catch (err) {
|
|
144
155
|
spinner.fail('Failed to switch environment');
|
package/src/commands/login.js
CHANGED
|
@@ -5,7 +5,7 @@ const chalk = require('chalk');
|
|
|
5
5
|
const ora = require('ora');
|
|
6
6
|
const inquirer = require('inquirer');
|
|
7
7
|
const axios = require('axios');
|
|
8
|
-
const { storeCredentials, hasValidCredentials, setProjectId, setUserInfo, getEnvironment } = require('../config/credentials');
|
|
8
|
+
const { storeCredentials, getCredentials, hasValidCredentials, setProjectId, setUserInfo, getEnvironment } = require('../config/credentials');
|
|
9
9
|
const { getApiBaseUrl } = require('../api/client');
|
|
10
10
|
const { getEnvironmentConfig } = require('../config/environments');
|
|
11
11
|
|
|
@@ -87,8 +87,10 @@ async function login() {
|
|
|
87
87
|
? new Date(Date.now() + parseInt(expiresIn) * 1000)
|
|
88
88
|
: new Date(Date.now() + 3600 * 1000); // Default 1 hour
|
|
89
89
|
|
|
90
|
-
//
|
|
90
|
+
// CR-2026-061: Preserve environment when storing new credentials
|
|
91
|
+
const existingCreds = await getCredentials();
|
|
91
92
|
await storeCredentials({
|
|
93
|
+
environment: existingCreds?.environment, // Preserve environment
|
|
92
94
|
accessToken,
|
|
93
95
|
refreshToken,
|
|
94
96
|
expiresAt: expiresAt.toISOString()
|