Skip to content

Commit 83fa379

Browse files
committed
Use temporary client for login
1 parent a5efbab commit 83fa379

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/commands.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getErrorMessage } from "coder/site/src/api/errors"
33
import { User, Workspace, WorkspaceAgent } from "coder/site/src/api/typesGenerated"
44
import * as vscode from "vscode"
55
import { extractAgents } from "./api-helper"
6+
import { makeCoderSdk } from "./api"
67
import { CertificateError } from "./error"
78
import { Remote } from "./remote"
89
import { Storage } from "./storage"
@@ -94,7 +95,10 @@ export class Commands {
9495
if (!url) {
9596
return
9697
}
97-
this.restClient.setHost(url)
98+
99+
// Use a temporary client to avoid messing with the global one while trying
100+
// to log in.
101+
const restClient = await makeCoderSdk(url, undefined, this.storage)
98102

99103
let user: User | undefined
100104
let token: string | undefined = args.length >= 2 ? args[1] : undefined
@@ -112,9 +116,9 @@ export class Commands {
112116
value: await this.storage.getSessionToken(),
113117
ignoreFocusOut: true,
114118
validateInput: async (value) => {
115-
this.restClient.setSessionToken(value)
119+
restClient.setSessionToken(value)
116120
try {
117-
user = await this.restClient.getAuthenticatedUser()
121+
user = await restClient.getAuthenticatedUser()
118122
if (!user) {
119123
throw new Error("Failed to get authenticated user")
120124
}
@@ -145,6 +149,10 @@ export class Commands {
145149
return
146150
}
147151

152+
// The URL and token are good; authenticate the global client.
153+
this.restClient.setHost(url)
154+
this.restClient.setSessionToken(token)
155+
148156
// Store these to be used in later sessions and in the cli.
149157
await this.storage.setURL(url)
150158
await this.storage.setSessionToken(token)

0 commit comments

Comments
 (0)