@@ -3,6 +3,7 @@ import { getErrorMessage } from "coder/site/src/api/errors"
3
3
import { User , Workspace , WorkspaceAgent } from "coder/site/src/api/typesGenerated"
4
4
import * as vscode from "vscode"
5
5
import { extractAgents } from "./api-helper"
6
+ import { makeCoderSdk } from "./api"
6
7
import { CertificateError } from "./error"
7
8
import { Remote } from "./remote"
8
9
import { Storage } from "./storage"
@@ -94,7 +95,10 @@ export class Commands {
94
95
if ( ! url ) {
95
96
return
96
97
}
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 )
98
102
99
103
let user : User | undefined
100
104
let token : string | undefined = args . length >= 2 ? args [ 1 ] : undefined
@@ -112,9 +116,9 @@ export class Commands {
112
116
value : await this . storage . getSessionToken ( ) ,
113
117
ignoreFocusOut : true ,
114
118
validateInput : async ( value ) => {
115
- this . restClient . setSessionToken ( value )
119
+ restClient . setSessionToken ( value )
116
120
try {
117
- user = await this . restClient . getAuthenticatedUser ( )
121
+ user = await restClient . getAuthenticatedUser ( )
118
122
if ( ! user ) {
119
123
throw new Error ( "Failed to get authenticated user" )
120
124
}
@@ -145,6 +149,10 @@ export class Commands {
145
149
return
146
150
}
147
151
152
+ // The URL and token are good; authenticate the global client.
153
+ this . restClient . setHost ( url )
154
+ this . restClient . setSessionToken ( token )
155
+
148
156
// Store these to be used in later sessions and in the cli.
149
157
await this . storage . setURL ( url )
150
158
await this . storage . setSessionToken ( token )
0 commit comments