cli-tunnel 1.2.0-beta.3 → 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 +48 -27
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -473,38 +473,38 @@ async function main() {
|
|
|
473
473
|
console.log(`\n ${DIM}More info: https://aka.ms/devtunnels/doc${RESET}`);
|
|
474
474
|
console.log(` ${DIM}Continuing without tunnel (local only)...${RESET}\n`);
|
|
475
475
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
476
|
+
}
|
|
477
|
+
if (devtunnelInstalled) {
|
|
478
|
+
// Check if logged in before attempting tunnel creation
|
|
479
|
+
try {
|
|
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');
|
|
483
483
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
}
|
|
496
|
-
catch {
|
|
497
|
-
console.log(`\n ${YELLOW}⚠${RESET} Login failed. Run manually: ${GREEN}devtunnel user login${RESET}\n`);
|
|
498
|
-
console.log(` ${DIM}Continuing without tunnel (local only)...${RESET}\n`);
|
|
499
|
-
devtunnelInstalled = false;
|
|
500
|
-
}
|
|
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`);
|
|
501
496
|
}
|
|
502
|
-
|
|
503
|
-
console.log(`\n ${
|
|
497
|
+
catch {
|
|
498
|
+
console.log(`\n ${YELLOW}⚠${RESET} Login failed. Run manually: ${GREEN}devtunnel user login${RESET}\n`);
|
|
504
499
|
console.log(` ${DIM}Continuing without tunnel (local only)...${RESET}\n`);
|
|
505
500
|
devtunnelInstalled = false;
|
|
506
501
|
}
|
|
507
502
|
}
|
|
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
|
+
}
|
|
508
508
|
}
|
|
509
509
|
}
|
|
510
510
|
if (devtunnelInstalled) {
|
|
@@ -547,7 +547,28 @@ async function main() {
|
|
|
547
547
|
catch { } });
|
|
548
548
|
}
|
|
549
549
|
catch (err) {
|
|
550
|
-
|
|
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
|
+
}
|
|
551
572
|
}
|
|
552
573
|
} // end if (devtunnelInstalled)
|
|
553
574
|
}
|