@@ -47,7 +47,7 @@ const INITIAL_EVENT_TIMEOUT_MS = 500;
47
47
48
48
/** Custom AuthEventManager that adds passive listeners to events */
49
49
export class CordovaAuthEventManager extends AuthEventManager {
50
- private readonly passiveListeners : Set < ( e : AuthEvent ) => void > = new Set ( ) ;
50
+ private readonly passiveListeners = new Set < ( e : AuthEvent ) => void > ( ) ;
51
51
52
52
addPassiveListener ( cb : ( e : AuthEvent ) => void ) : void {
53
53
this . passiveListeners . add ( cb ) ;
@@ -73,18 +73,19 @@ export class CordovaAuthEventManager extends AuthEventManager {
73
73
74
74
class CordovaPopupRedirectResolver implements PopupRedirectResolver {
75
75
readonly _redirectPersistence = browserSessionPersistence ;
76
- private readonly eventManagers : Record < string , CordovaAuthEventManager > = { } ;
76
+ private readonly eventManagers = new Map < string , CordovaAuthEventManager > ( ) ;
77
77
78
78
_completeRedirectFn : ( ) => Promise < null > = async ( ) => null ;
79
79
80
80
async _initialize ( auth : Auth ) : Promise < CordovaAuthEventManager > {
81
81
const key = auth . _key ( ) ;
82
- if ( ! this . eventManagers [ key ] ) {
83
- const manager = new CordovaAuthEventManager ( auth ) ;
84
- this . eventManagers [ key ] = manager ;
82
+ let manager = this . eventManagers . get ( key ) ;
83
+ if ( ! manager ) {
84
+ manager = new CordovaAuthEventManager ( auth ) ;
85
+ this . eventManagers . set ( key , manager ) ;
85
86
this . attachCallbackListeners ( auth , manager ) ;
86
87
}
87
- return this . eventManagers [ key ] ;
88
+ return manager ;
88
89
}
89
90
90
91
_openPopup ( auth : Auth ) : Promise < AuthPopup > {
@@ -111,21 +112,11 @@ class CordovaPopupRedirectResolver implements PopupRedirectResolver {
111
112
}
112
113
113
114
private attachCallbackListeners ( auth : Auth , manager : AuthEventManager ) : void {
114
- const noEvent : AuthEvent = {
115
- type : AuthEventType . UNKNOWN ,
116
- eventId : null ,
117
- sessionId : null ,
118
- urlResponse : null ,
119
- postBody : null ,
120
- tenantId : null ,
121
- error : _createError ( AuthErrorCode . NO_AUTH_EVENT )
122
- } ;
123
-
124
115
const noEventTimeout = setTimeout ( async ( ) => {
125
116
// We didn't see that initial event. Clear any pending object and
126
117
// dispatch no event
127
118
await _getAndRemoveEvent ( auth ) ;
128
- manager . onEvent ( noEvent ) ;
119
+ manager . onEvent ( generateNoEvent ( ) ) ;
129
120
} , INITIAL_EVENT_TIMEOUT_MS ) ;
130
121
131
122
const universalLinksCb = async (
@@ -135,14 +126,20 @@ class CordovaPopupRedirectResolver implements PopupRedirectResolver {
135
126
clearTimeout ( noEventTimeout ) ;
136
127
137
128
const partialEvent = await _getAndRemoveEvent ( auth ) ;
138
- let finalEvent : AuthEvent | null = noEvent ;
139
- // Start with the noEvent
129
+ let finalEvent : AuthEvent | null = null ;
140
130
if ( partialEvent && eventData ?. [ 'url' ] ) {
141
131
finalEvent = _eventFromPartialAndUrl ( partialEvent , eventData [ 'url' ] ) ;
142
132
}
143
- manager . onEvent ( finalEvent || noEvent ) ;
133
+
134
+ // If finalEvent is never filled, trigger with no event
135
+ manager . onEvent ( finalEvent || generateNoEvent ( ) ) ;
144
136
} ;
145
137
138
+ // Universal links subscriber doesn't exist for iOS, so we need to check
139
+ if ( typeof universalLinks . subscribe === 'function' ) {
140
+ universalLinks . subscribe ( null , universalLinksCb ) ;
141
+ }
142
+
146
143
// iOS 7 or 8 custom URL schemes.
147
144
// This is also the current default behavior for iOS 9+.
148
145
// For this to work, cordova-plugin-customurlscheme needs to be installed.
@@ -169,11 +166,6 @@ class CordovaPopupRedirectResolver implements PopupRedirectResolver {
169
166
}
170
167
}
171
168
} ;
172
-
173
- // Universal links subscriber doesn't exist for iOS, so we need to check
174
- if ( typeof universalLinks . subscribe === 'function' ) {
175
- universalLinks . subscribe ( null , universalLinksCb ) ;
176
- }
177
169
}
178
170
}
179
171
@@ -184,3 +176,15 @@ class CordovaPopupRedirectResolver implements PopupRedirectResolver {
184
176
* @public
185
177
*/
186
178
export const cordovaPopupRedirectResolver : externs . PopupRedirectResolver = CordovaPopupRedirectResolver ;
179
+
180
+ function generateNoEvent ( ) : AuthEvent {
181
+ return {
182
+ type : AuthEventType . UNKNOWN ,
183
+ eventId : null ,
184
+ sessionId : null ,
185
+ urlResponse : null ,
186
+ postBody : null ,
187
+ tenantId : null ,
188
+ error : _createError ( AuthErrorCode . NO_AUTH_EVENT )
189
+ } ;
190
+ }
0 commit comments