@@ -151,6 +151,12 @@ define(function (require, exports, module) {
151
151
PreferencesManager . stateManager . set ( PREF_USER_PROFILE_VERSION , crypto . randomUUID ( ) ) ;
152
152
}
153
153
154
+ /**
155
+ * Calls remote resolveBrowserSession endpoint to verify login status. should not be used frequently.
156
+ * @param silentCheck
157
+ * @returns {Promise<void> }
158
+ * @private
159
+ */
154
160
async function _verifyBrowserLogin ( silentCheck = false ) {
155
161
console . log ( "Verifying browser login status..." ) ;
156
162
@@ -161,28 +167,36 @@ define(function (require, exports, module) {
161
167
isLoggedInUser = true ;
162
168
ProfileMenu . setLoggedIn ( userProfile . profileIcon . initials , userProfile . profileIcon . color ) ;
163
169
console . log ( "Browser login verified for:" , userProfile . email ) ;
170
+ Metrics . countEvent ( Metrics . EVENT_TYPE . AUTH , "browser" , "OKLogin" ) ;
164
171
return ;
165
172
}
166
173
167
- // User is not logged in or error occurred
174
+ // User is not logged in or error occurred if here
168
175
if ( resolveResponse . err === ERR_NOT_LOGGED_IN ) {
169
176
console . log ( "No browser session found. Not logged in" ) ;
170
- // Only reset UI state if this is not a silent background check
171
- if ( ! silentCheck ) {
172
- _resetBrowserLogin ( ) ;
173
- } else {
174
- // For silent checks, just update the internal state
175
- isLoggedInUser = false ;
176
- userProfile = null ;
177
- }
177
+ Metrics . countEvent ( Metrics . EVENT_TYPE . AUTH , "browser" , "NotLoggedIn" ) ;
178
+ _handleLoginError ( silentCheck ) ;
179
+ return ;
180
+ }
181
+
182
+ if ( resolveResponse . err === ERR_INVALID ) {
183
+ console . log ( "Invalid auth token, resetting login state" ) ;
184
+ Metrics . countEvent ( Metrics . EVENT_TYPE . AUTH , "browser" , "invalidLogin" ) ;
185
+ _handleLoginError ( silentCheck ) ;
178
186
return ;
179
187
}
180
188
181
189
// Other errors (network, retry later, etc.)
182
- console . log ( "Browser login verification failed:" , resolveResponse . err ) ;
190
+ console . log ( "Browser login verification failed (temporary):" , resolveResponse . err ) ;
191
+ Metrics . countEvent ( Metrics . EVENT_TYPE . AUTH , "browser" , "RetryLogin" ) ;
192
+ // Don't reset login state for temporary errors, regardless of silent check
193
+ }
194
+
195
+ function _handleLoginError ( silentCheck ) {
183
196
if ( ! silentCheck ) {
184
197
_resetBrowserLogin ( ) ;
185
198
} else {
199
+ // For silent checks, just update the internal state
186
200
isLoggedInUser = false ;
187
201
userProfile = null ;
188
202
}
@@ -379,13 +393,15 @@ define(function (require, exports, module) {
379
393
return ;
380
394
}
381
395
382
- // Always verify login on browser app start (silent check to avoid closing popups)
383
- _verifyBrowserLogin ( true ) . catch ( console . error ) ;
396
+ // Always verify login on browser app start
397
+ _verifyBrowserLogin ( ) . catch ( console . error ) ;
384
398
385
399
// Watch for profile changes from other windows/tabs
386
400
const pref = PreferencesManager . stateManager . definePreference ( PREF_USER_PROFILE_VERSION , 'string' , '0' ) ;
387
401
pref . watchExternalChanges ( ) ;
388
- pref . on ( 'change' , _verifyBrowserLogin ) ;
402
+ pref . on ( 'change' , ( ) => {
403
+ _verifyBrowserLogin ( true ) . catch ( console . error ) ;
404
+ } ) ;
389
405
390
406
// Note: We don't do automatic verification on page focus to avoid server overload.
391
407
// Automatic checks are only done during the login waiting dialog period.
@@ -402,7 +418,9 @@ define(function (require, exports, module) {
402
418
LoginService . signInToAccount = signInToBrowser ;
403
419
LoginService . signOutAccount = signOutBrowser ;
404
420
LoginService . getProfile = getProfile ;
405
- LoginService . verifyLoginStatus = ( ) => _verifyBrowserLogin ( false ) ;
421
+ // verifyLoginStatus Calls remote resolveBrowserSession endpoint to verify. should not be used frequently.
422
+ // All users are required to use isLoggedIn API instead.
423
+ LoginService . _verifyLoginStatus = ( ) => _verifyBrowserLogin ( false ) ;
406
424
LoginService . getAccountBaseURL = _getAccountBaseURL ;
407
425
init ( ) ;
408
426
}
0 commit comments