@telelabsai/ship 1.1.10 → 1.1.11
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/cli/commands/auth.js +30 -5
- package/package.json +1 -1
package/cli/commands/auth.js
CHANGED
|
@@ -14,15 +14,40 @@ const DASHBOARD_URL = process.env.SHIP_DASHBOARD_URL || 'http://localhost:3000';
|
|
|
14
14
|
* ship auth login — open browser to authorize CLI
|
|
15
15
|
*/
|
|
16
16
|
function login() {
|
|
17
|
-
// Check if already authenticated
|
|
17
|
+
// Check if already authenticated and token is still valid
|
|
18
18
|
const existing = loadCredentials();
|
|
19
19
|
if (existing?.token) {
|
|
20
|
-
console.log(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
console.log(' Checking existing session...\n');
|
|
21
|
+
// Validate token with server
|
|
22
|
+
const lib = DASHBOARD_URL.startsWith('https') ? require('https') : require('http');
|
|
23
|
+
const req = lib.get(`${DASHBOARD_URL}/api/cli/workspaces`, {
|
|
24
|
+
headers: { 'Authorization': `Bearer ${existing.token}`, 'User-Agent': 'Ship-CLI' },
|
|
25
|
+
}, (res) => {
|
|
26
|
+
if (res.statusCode === 200) {
|
|
27
|
+
console.log(` Already authenticated as ${existing.user?.name || existing.user?.email || 'user'}.`);
|
|
28
|
+
console.log(` Token: ${existing.token.slice(0, 12)}••••••`);
|
|
29
|
+
console.log(' Run: ship auth logout to re-authenticate.\n');
|
|
30
|
+
process.exit(0);
|
|
31
|
+
} else {
|
|
32
|
+
// Token revoked or expired — clear and re-auth
|
|
33
|
+
console.log(' Session expired or revoked. Re-authenticating...\n');
|
|
34
|
+
if (fs.existsSync(CREDENTIALS_FILE)) fs.unlinkSync(CREDENTIALS_FILE);
|
|
35
|
+
startAuthFlow();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
req.on('error', () => {
|
|
39
|
+
// Can't reach server — trust local credentials
|
|
40
|
+
console.log(` Already authenticated as ${existing.user?.name || existing.user?.email || 'user'} (offline).`);
|
|
41
|
+
console.log(' Run: ship auth logout to re-authenticate.\n');
|
|
42
|
+
process.exit(0);
|
|
43
|
+
});
|
|
44
|
+
return;
|
|
24
45
|
}
|
|
25
46
|
|
|
47
|
+
startAuthFlow();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function startAuthFlow() {
|
|
26
51
|
console.log(' Opening browser to authorize Ship CLI...\n');
|
|
27
52
|
|
|
28
53
|
// Start a local HTTP server to receive the callback
|