1919/*global logger*/
2020
2121define ( function ( require , exports , module ) {
22+ require ( "./login-service" ) ; // after this, loginService will be in KernalModeTrust
23+
2224 const EventDispatcher = require ( "utils/EventDispatcher" ) ,
2325 PreferencesManager = require ( "preferences/PreferencesManager" ) ,
2426 Metrics = require ( "utils/Metrics" ) ,
@@ -27,7 +29,6 @@ define(function (require, exports, module) {
2729 Strings = require ( "strings" ) ,
2830 NativeApp = require ( "utils/NativeApp" ) ,
2931 ProfileMenu = require ( "./profile-menu" ) ,
30- LoginService = require ( "./login-service" ) ,
3132 Mustache = require ( "thirdparty/mustache/mustache" ) ,
3233 NodeConnector = require ( "NodeConnector" ) ,
3334 otpDialogTemplate = require ( "text!./html/otp-dialog.html" ) ;
@@ -37,11 +38,8 @@ define(function (require, exports, module) {
3738 // integrated extensions will have access to kernal mode, but not external extensions
3839 throw new Error ( "Login service should have access to KernalModeTrust. Cannot boot without trust ring" ) ;
3940 }
40- const secureExports = { } ;
41- // Only set loginService for native apps to avoid conflict with browser login
42- if ( Phoenix . isNativeApp ) {
43- KernalModeTrust . loginService = secureExports ;
44- }
41+ const LoginService = KernalModeTrust . loginService ;
42+
4543 // user profile is something like "apiKey": "uuid...", validationCode: "dfdf", "firstName":"Aa","lastName":"bb",
4644 // "email":"[email protected] ", "customerID":"uuid...","loginTime":1750074393853, 4745 // "profileIcon":{"color":"#14b8a6","initials":"AB"}
@@ -51,12 +49,11 @@ define(function (require, exports, module) {
5149 // just used as trigger to notify different windows about user profile changes
5250 const PREF_USER_PROFILE_VERSION = "userProfileVersion" ;
5351
54- EventDispatcher . makeEventDispatcher ( exports ) ;
55- EventDispatcher . makeEventDispatcher ( secureExports ) ;
56-
5752 const _EVT_PAGE_FOCUSED = "page_focused" ;
53+ const focusWatcher = { } ;
54+ EventDispatcher . makeEventDispatcher ( focusWatcher ) ;
5855 $ ( window ) . focus ( function ( ) {
59- exports . trigger ( _EVT_PAGE_FOCUSED ) ;
56+ focusWatcher . trigger ( _EVT_PAGE_FOCUSED ) ;
6057 } ) ;
6158
6259 const AUTH_CONNECTOR_ID = "ph_auth" ;
@@ -320,7 +317,7 @@ define(function (require, exports, module) {
320317 }
321318 }
322319 let isAutoSignedIn = false ;
323- exports . on ( _EVT_PAGE_FOCUSED , checkLoginStatus ) ;
320+ focusWatcher . on ( _EVT_PAGE_FOCUSED , checkLoginStatus ) ;
324321 async function _AutoSignedIn ( ) {
325322 isAutoSignedIn = true ;
326323 await checkLoginStatus ( ) ;
@@ -329,7 +326,7 @@ define(function (require, exports, module) {
329326
330327 // Clean up when dialog is closed
331328 dialog . done ( function ( ) {
332- exports . off ( _EVT_PAGE_FOCUSED , checkLoginStatus ) ;
329+ focusWatcher . off ( _EVT_PAGE_FOCUSED , checkLoginStatus ) ;
333330 authNodeConnector . off ( EVENT_CONNECTED , _AutoSignedIn ) ;
334331 clearTimeout ( closeTimeout ) ;
335332 Metrics . countEvent ( Metrics . EVENT_TYPE . AUTH ,
@@ -411,15 +408,13 @@ define(function (require, exports, module) {
411408 // Only set exports for native apps to avoid conflict with browser login
412409 if ( Phoenix . isNativeApp ) {
413410 init ( ) ;
414- // kernal exports
415- secureExports . isLoggedIn = isLoggedIn ;
416- secureExports . signInToAccount = signInToAccount ;
417- secureExports . signOutAccount = signOutAccount ;
418- secureExports . getProfile = getProfile ;
419- secureExports . verifyLoginStatus = ( ) => _verifyLogin ( false ) ;
420- secureExports . getAccountBaseURL = getAccountBaseURL ;
421- secureExports . getEntitlements = LoginService . getEntitlements ;
422- secureExports . EVENT_ENTITLEMENTS_CHANGED = LoginService . EVENT_ENTITLEMENTS_CHANGED ;
411+ // kernal exports - add to existing KernalModeTrust.loginService from login-service.js
412+ LoginService . isLoggedIn = isLoggedIn ;
413+ LoginService . signInToAccount = signInToAccount ;
414+ LoginService . signOutAccount = signOutAccount ;
415+ LoginService . getProfile = getProfile ;
416+ LoginService . verifyLoginStatus = ( ) => _verifyLogin ( false ) ;
417+ LoginService . getAccountBaseURL = getAccountBaseURL ;
423418 }
424419
425420 // public exports
0 commit comments