@@ -99,15 +99,25 @@ export class AuthUtil implements IAuthProvider {
99
99
* {@link notifySelectDeveloperProfile} needs {@link refreshState} to run so it can set
100
100
* the Bearer Token in the LSP first.
101
101
*/
102
- startedConnected = false
102
+ didStartSignedIn = false
103
103
104
104
async restore ( ) {
105
105
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 ) {
111
121
await this . refreshState ( )
112
122
}
113
123
}
@@ -302,7 +312,7 @@ export class AuthUtil implements IAuthProvider {
302
312
}
303
313
304
314
private tryNotifySelectDeveloperProfile = once ( async ( ) => {
305
- if ( this . regionProfileManager . requireProfileSelection ( ) && this . startedConnected ) {
315
+ if ( this . regionProfileManager . requireProfileSelection ( ) && this . didStartSignedIn ) {
306
316
await notifySelectDeveloperProfile ( )
307
317
}
308
318
} )
0 commit comments