feat(cli): Fixes CLI authentication redirect error (#6835)

* fix: redirect for CLI after login

* fix: redirect for CLI after login
This commit is contained in:
Ara authored and GitHub committed 2025-10-14 12:42:59 -07:00
1 parent 08286a8465
commit 7b7a006123
1 file changed
+16 -3
+16 -3
View File
@@ -162,7 +162,18 @@ export class AuthHandler {
// Use SharedUriHandler directly - it handles all validation and processing
const success = await SharedUriHandler.handleUri(fullUrl)
const redirectUri = (await HostProvider.env.getIdeRedirectUri({})).value
// Try to get redirect URI, but don't fail if not implemented (CLI/JetBrains)
let redirectUri: string | undefined
try {
redirectUri = (await HostProvider.env.getIdeRedirectUri({})).value
console.log("AuthHandler: Got redirect URI:", redirectUri)
} catch (error) {
// CLI or JetBrains mode - redirect not available
console.log("AuthHandler: No redirect URI available (CLI/JetBrains mode)")
redirectUri = undefined
}
const html = createAuthSucceededHtml(redirectUri)
if (success) {
@@ -206,6 +217,8 @@ export class AuthHandler {
function createAuthSucceededHtml(redirectUri?: string): string {
const redirect = redirectUri ? `<script>setTimeout(() => { window.location.href = '${redirectUri}'; }, 1000);</script>` : ""
// Use "terminal" for CLI (no redirect), "IDE" for VSCode/JetBrains (with redirect)
const platform = redirectUri ? "IDE" : "terminal"
const html = `<!DOCTYPE html>
<html lang="en">
@@ -305,8 +318,8 @@ function createAuthSucceededHtml(redirectUri?: string): string {
<div class="container">
<div class="checkmark"></div>
<h1>Authentication Successful</h1>
<p>Your authentication token has been securely sent back to your IDE. You can now return to your development environment to continue working.</p>
<div class="countdown">Feel free to close this window and continue in your IDE</div>
<p>Your authentication token has been securely sent back to your ${platform}. You can now return to your development environment to continue working.</p>
<div class="countdown">Feel free to close this window and continue in your ${platform}</div>
</div>
</body>
</html>`