cli-tunnel 1.2.0-beta.4 → 1.2.0-beta.5
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/dist/index.js +45 -30
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -475,42 +475,36 @@ async function main() {
|
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
477
|
if (devtunnelInstalled) {
|
|
478
|
+
// Check if logged in before attempting tunnel creation
|
|
478
479
|
try {
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
if (userInfo.includes('not logged in') || userInfo.includes('No user') || userInfo.includes('Anonymous')) {
|
|
483
|
-
throw new Error('not logged in');
|
|
484
|
-
}
|
|
480
|
+
const userInfo = execFileSync('devtunnel', ['user', 'show'], { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] });
|
|
481
|
+
if (userInfo.includes('not logged in') || userInfo.includes('No user') || userInfo.includes('Anonymous')) {
|
|
482
|
+
throw new Error('not logged in');
|
|
485
483
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
catch {
|
|
499
|
-
console.log(`\n ${YELLOW}⚠${RESET} Login failed. Run manually: ${GREEN}devtunnel user login${RESET}\n`);
|
|
500
|
-
console.log(` ${DIM}Continuing without tunnel (local only)...${RESET}\n`);
|
|
501
|
-
devtunnelInstalled = false;
|
|
502
|
-
}
|
|
484
|
+
}
|
|
485
|
+
catch {
|
|
486
|
+
console.log(`\n ${YELLOW}⚠ devtunnel not authenticated.${RESET}\n`);
|
|
487
|
+
const loginAnswer = await askUser(` Would you like to log in now? [Y/n] `);
|
|
488
|
+
if (loginAnswer === '' || loginAnswer === 'y' || loginAnswer === 'yes') {
|
|
489
|
+
try {
|
|
490
|
+
const loginProc = spawn('devtunnel', ['user', 'login'], { stdio: 'inherit' });
|
|
491
|
+
await new Promise((resolve, reject) => {
|
|
492
|
+
loginProc.on('close', (code) => code === 0 ? resolve() : reject(new Error(`Login exited with code ${code}`)));
|
|
493
|
+
loginProc.on('error', reject);
|
|
494
|
+
});
|
|
495
|
+
console.log(`\n ${GREEN}✓${RESET} Logged in successfully!\n`);
|
|
503
496
|
}
|
|
504
|
-
|
|
505
|
-
console.log(`\n ${
|
|
497
|
+
catch {
|
|
498
|
+
console.log(`\n ${YELLOW}⚠${RESET} Login failed. Run manually: ${GREEN}devtunnel user login${RESET}\n`);
|
|
506
499
|
console.log(` ${DIM}Continuing without tunnel (local only)...${RESET}\n`);
|
|
507
500
|
devtunnelInstalled = false;
|
|
508
501
|
}
|
|
509
502
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
503
|
+
else {
|
|
504
|
+
console.log(`\n ${DIM}Run this once to log in: ${GREEN}devtunnel user login${RESET}`);
|
|
505
|
+
console.log(` ${DIM}Continuing without tunnel (local only)...${RESET}\n`);
|
|
506
|
+
devtunnelInstalled = false;
|
|
507
|
+
}
|
|
514
508
|
}
|
|
515
509
|
}
|
|
516
510
|
if (devtunnelInstalled) {
|
|
@@ -553,7 +547,28 @@ async function main() {
|
|
|
553
547
|
catch { } });
|
|
554
548
|
}
|
|
555
549
|
catch (err) {
|
|
556
|
-
|
|
550
|
+
const errMsg = err.message || '';
|
|
551
|
+
// Detect auth failure at create time (expired token, anonymous, etc.)
|
|
552
|
+
if (errMsg.includes('Anonymous') || errMsg.includes('Unauthorized') || errMsg.includes('not permitted')) {
|
|
553
|
+
console.log(`\n ${YELLOW}⚠ devtunnel session expired or not authenticated.${RESET}\n`);
|
|
554
|
+
const loginAnswer = await askUser(` Would you like to log in now? [Y/n] `);
|
|
555
|
+
if (loginAnswer === '' || loginAnswer === 'y' || loginAnswer === 'yes') {
|
|
556
|
+
try {
|
|
557
|
+
const loginProc = spawn('devtunnel', ['user', 'login'], { stdio: 'inherit' });
|
|
558
|
+
await new Promise((resolve, reject) => {
|
|
559
|
+
loginProc.on('close', (code) => code === 0 ? resolve() : reject(new Error(`Login exited with code ${code}`)));
|
|
560
|
+
loginProc.on('error', reject);
|
|
561
|
+
});
|
|
562
|
+
console.log(`\n ${GREEN}✓${RESET} Logged in! Please run cli-tunnel again to create the tunnel.\n`);
|
|
563
|
+
}
|
|
564
|
+
catch {
|
|
565
|
+
console.log(`\n ${YELLOW}⚠${RESET} Login failed. Run manually: ${GREEN}devtunnel user login${RESET}\n`);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
else {
|
|
570
|
+
console.log(` ${YELLOW}⚠${RESET} Tunnel failed: ${errMsg}\n`);
|
|
571
|
+
}
|
|
557
572
|
}
|
|
558
573
|
} // end if (devtunnelInstalled)
|
|
559
574
|
}
|