Skip to content

Suppress login failure dialog on autologin #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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