@@ -184,6 +184,12 @@ fireauth.Auth = function(app) {
184
184
* is currently only used to log FirebaseUI.
185
185
*/
186
186
this . frameworks_ = [ ] ;
187
+
188
+ /**
189
+ * @private {?fireauth.constants.EmulatorSettings} The current
190
+ * emulator settings.
191
+ */
192
+ this . emulatorConfig_ = null ;
187
193
} ;
188
194
goog . inherits ( fireauth . Auth , goog . events . EventTarget ) ;
189
195
@@ -202,6 +208,20 @@ fireauth.Auth.LanguageCodeChangeEvent = function(languageCode) {
202
208
goog . inherits ( fireauth . Auth . LanguageCodeChangeEvent , goog . events . Event ) ;
203
209
204
210
211
+ /**
212
+ * Emulator config change custom event.
213
+ * @param {?fireauth.constants.EmulatorSettings } emulatorConfig The new
214
+ * emulator settings.
215
+ * @constructor
216
+ * @extends {goog.events.Event }
217
+ */
218
+ fireauth . Auth . EmulatorConfigChangeEvent = function ( emulatorConfig ) {
219
+ goog . events . Event . call ( this , fireauth . constants . AuthEventType . EMULATOR_CONFIG_CHANGED ) ;
220
+ this . emulatorConfig = emulatorConfig ;
221
+ } ;
222
+ goog . inherits ( fireauth . Auth . EmulatorConfigChangeEvent , goog . events . Event ) ;
223
+
224
+
205
225
/**
206
226
* Framework change custom event.
207
227
* @param {!Array<string> } frameworks The new frameworks array.
@@ -272,6 +292,34 @@ fireauth.Auth.prototype.useDeviceLanguage = function() {
272
292
} ;
273
293
274
294
295
+ /**
296
+ * Sets the emulator configuration (go/firebase-emulator-connection-api).
297
+ * @param {string } hostname The hostname for the Auth emulator.
298
+ * @param {number } port The port for the Auth emulator.
299
+ */
300
+ fireauth . Auth . prototype . useEmulator = function ( hostname , port ) {
301
+ // Don't do anything if no change detected.
302
+ if ( ! this . emulatorConfig_ ||
303
+ hostname !== this . emulatorConfig_ . hostname ||
304
+ port !== this . emulatorConfig_ . port ) {
305
+ this . emulatorConfig_ = { hostname : hostname , port : port } ;
306
+ // Disable app verification.
307
+ this . settings_ ( ) . setAppVerificationDisabledForTesting ( true ) ;
308
+ // Update custom Firebase locale field.
309
+ this . rpcHandler_ . updateEmulatorConfig ( this . emulatorConfig_ ) ;
310
+ // Notify external language code change listeners.
311
+ this . notifyEmulatorConfigListeners_ ( ) ;
312
+ }
313
+ }
314
+
315
+ /**
316
+ * @return {?fireauth.constants.EmulatorSettings }
317
+ */
318
+ fireauth . Auth . prototype . getEmulatorConfig = function ( ) {
319
+ return this . emulatorConfig_ ;
320
+ }
321
+
322
+
275
323
/**
276
324
* @param {string } frameworkId The framework identifier.
277
325
*/
@@ -396,7 +444,15 @@ fireauth.Auth.prototype.notifyLanguageCodeListeners_ = function() {
396
444
} ;
397
445
398
446
399
-
447
+ /**
448
+ * Notifies all external listeners of the emulator config change.
449
+ * @private
450
+ */
451
+ fireauth . Auth . prototype . notifyEmulatorConfigListeners_ = function ( ) {
452
+ // Notify external listeners on the language code change.
453
+ this . dispatchEvent (
454
+ new fireauth . Auth . EmulatorConfigChangeEvent ( this . emulatorConfig_ ) ) ;
455
+ }
400
456
401
457
402
458
/**
@@ -449,7 +505,10 @@ fireauth.Auth.prototype.initAuthEventManager_ = function() {
449
505
// By this time currentUser should be ready if available and will be able
450
506
// to resolve linkWithRedirect if detected.
451
507
self . authEventManager_ = fireauth . AuthEventManager . getManager (
452
- authDomain , apiKey , self . app_ ( ) . name ) ;
508
+ authDomain ,
509
+ apiKey ,
510
+ self . app_ ( ) . name ,
511
+ self . emulatorConfig_ ) ;
453
512
// Subscribe Auth instance.
454
513
self . authEventManager_ . subscribe ( self ) ;
455
514
// Subscribe current user by enabling popup and redirect on that user.
@@ -471,7 +530,10 @@ fireauth.Auth.prototype.initAuthEventManager_ = function() {
471
530
/** @type {!fireauth.AuthUser } */ ( self . redirectUser_ ) ) ;
472
531
// Set the user Firebase frameworks for the redirect user.
473
532
self . setUserFramework_ (
474
- /** @type {!fireauth.AuthUser } */ ( self . redirectUser_ ) ) ;
533
+ /** @type {!fireauth.AuthUser } */ ( self . redirectUser_ ) ) ;
534
+ // Set the user Emulator configuration for the redirect user.
535
+ self . setUserEmulatorConfig_ (
536
+ /** @type {!fireauth.AuthUser } */ ( self . redirectUser_ ) ) ;
475
537
// Reference to redirect user no longer needed.
476
538
self . redirectUser_ = null ;
477
539
}
@@ -650,7 +712,8 @@ fireauth.Auth.prototype.signInWithPopup = function(provider) {
650
712
firebase . SDK_VERSION || null ,
651
713
null ,
652
714
null ,
653
- this . getTenantId ( ) ) ;
715
+ this . getTenantId ( ) ,
716
+ this . emulatorConfig_ ) ;
654
717
}
655
718
// The popup must have a name, otherwise when successive popups are triggered
656
719
// they will all render in the same instance and none will succeed since the
@@ -856,6 +919,7 @@ fireauth.Auth.prototype.signInWithIdTokenResponse =
856
919
options [ 'apiKey' ] = self . app_ ( ) . options [ 'apiKey' ] ;
857
920
options [ 'authDomain' ] = self . app_ ( ) . options [ 'authDomain' ] ;
858
921
options [ 'appName' ] = self . app_ ( ) . name ;
922
+ options [ 'emulatorConfig' ] = self . emulatorConfig_ ;
859
923
// Wait for state to be ready.
860
924
// This is used internally and is also used for redirect sign in so there is
861
925
// no need for waiting for redirect result to resolve since redirect result
@@ -911,6 +975,9 @@ fireauth.Auth.prototype.setCurrentUser_ = function(user) {
911
975
// Set the current frameworks used on the user and set current Auth instance
912
976
// as the framework change dispatcher.
913
977
this . setUserFramework_ ( user ) ;
978
+ // If a user is available, set the emulator config on it and set current
979
+ // Auth instance as emulator config change dispatcher.
980
+ this . setUserEmulatorConfig_ ( user ) ;
914
981
}
915
982
} ;
916
983
@@ -1179,6 +1246,22 @@ fireauth.Auth.prototype.setUserLanguage_ = function(user) {
1179
1246
} ;
1180
1247
1181
1248
1249
+ /**
1250
+ * Updates the emulator config on the provided user and configures the user
1251
+ * to listen to the Auth instance for any emulator config changes.
1252
+ * @param {!fireauth.AuthUser } user The user to whose emulator config needs
1253
+ * to be set.
1254
+ * @private
1255
+ */
1256
+ fireauth . Auth . prototype . setUserEmulatorConfig_ = function ( user ) {
1257
+ // Sets the current emulator config on the user.
1258
+ user . setEmulatorConfig ( this . emulatorConfig_ ) ;
1259
+ // Sets current Auth instance as emulator config change dispatcher on the
1260
+ // user.
1261
+ user . setEmulatorConfigChangeDispatcher ( this ) ;
1262
+ }
1263
+
1264
+
1182
1265
/**
1183
1266
* Handles user state changes.
1184
1267
* @param {!fireauth.AuthUser } user The user which triggered the state changes.
@@ -1679,6 +1762,17 @@ fireauth.Auth.prototype.app_ = function() {
1679
1762
} ;
1680
1763
1681
1764
1765
+
1766
+ /**
1767
+ * @return {!fireauth.AuthSettings } The AuthSettings object this auth object
1768
+ * is connected to.
1769
+ * @private
1770
+ */
1771
+ fireauth . Auth . prototype . settings_ = function ( ) {
1772
+ return this [ 'settings' ] ;
1773
+ }
1774
+
1775
+
1682
1776
/**
1683
1777
* @return {!fireauth.RpcHandler } The RPC handler.
1684
1778
*/
0 commit comments