@@ -183,8 +183,10 @@ fireauth.AuthUser =
183
183
// Get the client Auth endpoint used.
184
184
fireauth . constants . getEndpointConfig ( fireauth . constants . clientEndpoint ) ,
185
185
clientFullVersion ) ;
186
- if ( appOptions [ 'emulatorConfig' ] ) {
187
- this . rpcHandler_ . updateEmulatorConfig ( appOptions [ 'emulatorConfig' ] ) ;
186
+ /** @private {?fireauth.constants.EmulatorSettings} The emulator config */
187
+ this . emulatorConfig_ = appOptions [ 'emulatorConfig' ] || null ;
188
+ if ( this . emulatorConfig_ ) {
189
+ this . rpcHandler_ . updateEmulatorConfig ( this . emulatorConfig_ ) ;
188
190
}
189
191
// TODO: Consider having AuthUser take a fireauth.StsTokenManager
190
192
// instance instead of a token response but make sure lastAccessToken_ also
@@ -212,7 +214,7 @@ fireauth.AuthUser =
212
214
fireauth . util . isPopupRedirectSupported ( ) ) {
213
215
// Get the Auth event manager associated with this user.
214
216
this . authEventManager_ = fireauth . AuthEventManager . getManager (
215
- this . authDomain_ , this . apiKey_ , this . appName_ ) ;
217
+ this . authDomain_ , this . apiKey_ , this . appName_ , this . emulatorConfig_ ) ;
216
218
}
217
219
/** @private {!Array<!function(!fireauth.AuthUser):!goog.Promise>} The list of
218
220
* state change listeners. This is needed to make sure state changes are
@@ -312,7 +314,24 @@ fireauth.AuthUser.prototype.setLanguageCode = function(languageCode) {
312
314
*/
313
315
fireauth . AuthUser . prototype . setEmulatorConfig = function ( emulatorConfig ) {
314
316
// Update the emulator config.
317
+ this . emulatorConfig_ = emulatorConfig ;
315
318
this . rpcHandler_ . updateEmulatorConfig ( emulatorConfig ) ;
319
+
320
+ if ( this . authEventManager_ ) {
321
+ // We need to get a new auth event manager keyed with the new emulator
322
+ // config.
323
+ const oldManager = this . authEventManager_ ;
324
+
325
+ // If authEventManager_ was previously set, we know authDomain_ is set as
326
+ // well.
327
+ this . authEventManager_ = fireauth . AuthEventManager . getManager (
328
+ /** @type {string } */ ( this . authDomain_ ) , this . apiKey_ , this . appName_ ,
329
+ this . emulatorConfig_ ) ;
330
+ if ( this . popupRedirectEnabled_ ) {
331
+ oldManager . unsubscribe ( this ) ;
332
+ this . authEventManager_ . subscribe ( this ) ;
333
+ }
334
+ }
316
335
} ;
317
336
318
337
@@ -1823,7 +1842,8 @@ fireauth.AuthUser.prototype.runOperationWithPopup_ =
1823
1842
firebase . SDK_VERSION || null ,
1824
1843
null ,
1825
1844
null ,
1826
- this [ 'tenantId' ] ) ;
1845
+ this [ 'tenantId' ] ,
1846
+ this . emulatorConfig_ ) ;
1827
1847
}
1828
1848
// The popup must have a name, otherwise when successive popups are triggered
1829
1849
// they will all render in the same instance and none will succeed since the
0 commit comments