Skip to content

Commit e2c4197

Browse files
fix comments
- Fix docstring explaining refreshState fragility - Fix variable name Signed-off-by: nkomonen-amazon <[email protected]>
1 parent 779501f commit e2c4197

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

packages/core/src/codewhisperer/util/authUtil.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,25 @@ export class AuthUtil implements IAuthProvider {
9999
* {@link notifySelectDeveloperProfile} needs {@link refreshState} to run so it can set
100100
* the Bearer Token in the LSP first.
101101
*/
102-
startedConnected = false
102+
didStartSignedIn = false
103103

104104
async restore() {
105105
await this.session.restore()
106-
this.startedConnected = this.isConnected()
107-
108-
// HACK: The LSP should allow us to call refreshState multiple times, but for some reason it breaks.
109-
// isConnected somehow allows it to work. Assumption is that the LSP does not handle redundant calls nicely.
110-
if (!this.isConnected()) {
106+
this.didStartSignedIn = this.isConnected()
107+
108+
// HACK: We noticed that if calling `refreshState()` here when the user was already signed in, something broke.
109+
// So as a solution we only call it if they were not already signed in.
110+
//
111+
// But in the case where a user was already signed in, we allow `session.restore()` to trigger `refreshState()` through
112+
// event emitters.
113+
// This is unoptimal since `refreshState()` should be able to be called multiple times and still work.
114+
//
115+
// Because of this edge case, when `restore()` is called we cannot assume all Auth is setup when this function returns,
116+
// since we may still be waiting on the event emitter to trigger the expected functions.
117+
//
118+
// TODO: Figure out why removing the if statement below causes things to break. Maybe we just need to
119+
// promisify the call and any subsequent callers will not make a redundant call.
120+
if (!this.didStartSignedIn) {
111121
await this.refreshState()
112122
}
113123
}
@@ -302,7 +312,7 @@ export class AuthUtil implements IAuthProvider {
302312
}
303313

304314
private tryNotifySelectDeveloperProfile = once(async () => {
305-
if (this.regionProfileManager.requireProfileSelection() && this.startedConnected) {
315+
if (this.regionProfileManager.requireProfileSelection() && this.didStartSignedIn) {
306316
await notifySelectDeveloperProfile()
307317
}
308318
})

0 commit comments

Comments
 (0)