Skip to content

Commit

Permalink
Suppress login failure dialog on autologin (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronlehmann authored Dec 12, 2024
1 parent 34faac3 commit 3520710
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export class Commands {
const inputUrl = args[0]
const inputToken = args[1]
const inputLabel = args[2]
const isAutologin = typeof args[3] === "undefined" ? false : Boolean(args[3])

const url = await this.maybeAskUrl(inputUrl)
if (!url) {
Expand All @@ -155,7 +156,7 @@ export class Commands {
const label = typeof inputLabel === "undefined" ? toSafeHost(url) : inputLabel

// Try to get a token from the user, if we need one, and their user.
const res = await this.maybeAskToken(url, inputToken)
const res = await this.maybeAskToken(url, inputToken, isAutologin)
if (!res) {
return // The user aborted, or unable to auth.
}
Expand Down Expand Up @@ -202,7 +203,11 @@ export class Commands {
* token. Null means the user aborted or we were unable to authenticate with
* mTLS (in the latter case, an error notification will have been displayed).
*/
private async maybeAskToken(url: string, token: string): Promise<{ user: User; token: string } | null> {
private async maybeAskToken(
url: string,
token: string,
isAutologin: boolean,
): Promise<{ user: User; token: string } | null> {
const restClient = await makeCoderSdk(url, token, this.storage)
if (!needToken()) {
try {
Expand All @@ -212,11 +217,15 @@ export class Commands {
return { token: "", user }
} catch (err) {
const message = getErrorMessage(err, "no response from the server")
this.vscodeProposed.window.showErrorMessage("Failed to log in", {
detail: message,
modal: true,
useCustom: true,
})
if (isAutologin) {
this.storage.writeToCoderOutputChannel(`Failed to log in to Coder server: ${message}`)
} else {
this.vscodeProposed.window.showErrorMessage("Failed to log in to Coder server", {
detail: message,
modal: true,
useCustom: true,
})
}
// Invalid certificate, most likely.
return null
}
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
if (cfg.get("coder.autologin") === true) {
const defaultUrl = cfg.get("coder.defaultUrl") || process.env.CODER_URL
if (defaultUrl) {
vscode.commands.executeCommand("coder.login", defaultUrl)
vscode.commands.executeCommand("coder.login", defaultUrl, undefined, undefined, "true")
}
}
}
Expand Down

0 comments on commit 3520710

Please sign in to comment.