Skip to content

Commit c81cf82

Browse files
authored
[Auth] Update user to plumb through emulator config (#4966)
* Update user to plumb through emulator config * Add changeset * Force python2 for auth test generator
1 parent 8250047 commit c81cf82

File tree

4 files changed

+435
-7
lines changed

4 files changed

+435
-7
lines changed

.changeset/dry-spiders-destroy.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/auth": patch
3+
---
4+
5+
Fix bug where `linkWithPopup`, `linkWithRedirect`, `reauthenticateWithPopup`, and `reauthenticateWithRedirect` weren't correctly picking up the emulator configuration.

packages/auth/buildtools/generate_test_files.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ cd "$(dirname $(dirname "$0"))"
2525
mkdir -p generated
2626

2727
echo "Generating dependency file..."
28-
python ../../node_modules/google-closure-library/closure/bin/build/depswriter.py \
28+
python2 ../../node_modules/google-closure-library/closure/bin/build/depswriter.py \
2929
--root_with_prefix="test ../../../../test" \
3030
--root_with_prefix="src ../../../../src" \
3131
> generated/deps.js
3232

3333
echo "Generating test HTML files..."
34-
python ./buildtools/gen_test_html.py
35-
python ./buildtools/gen_all_tests_js.py > generated/all_tests.js
34+
python2 ./buildtools/gen_test_html.py
35+
python2 ./buildtools/gen_all_tests_js.py > generated/all_tests.js
3636

3737
echo "Done."

packages/auth/src/authuser.js

+24-4
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,10 @@ fireauth.AuthUser =
183183
// Get the client Auth endpoint used.
184184
fireauth.constants.getEndpointConfig(fireauth.constants.clientEndpoint),
185185
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_);
188190
}
189191
// TODO: Consider having AuthUser take a fireauth.StsTokenManager
190192
// instance instead of a token response but make sure lastAccessToken_ also
@@ -212,7 +214,7 @@ fireauth.AuthUser =
212214
fireauth.util.isPopupRedirectSupported()) {
213215
// Get the Auth event manager associated with this user.
214216
this.authEventManager_ = fireauth.AuthEventManager.getManager(
215-
this.authDomain_, this.apiKey_, this.appName_);
217+
this.authDomain_, this.apiKey_, this.appName_, this.emulatorConfig_);
216218
}
217219
/** @private {!Array<!function(!fireauth.AuthUser):!goog.Promise>} The list of
218220
* state change listeners. This is needed to make sure state changes are
@@ -312,7 +314,24 @@ fireauth.AuthUser.prototype.setLanguageCode = function(languageCode) {
312314
*/
313315
fireauth.AuthUser.prototype.setEmulatorConfig = function(emulatorConfig) {
314316
// Update the emulator config.
317+
this.emulatorConfig_ = emulatorConfig;
315318
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+
}
316335
};
317336

318337

@@ -1823,7 +1842,8 @@ fireauth.AuthUser.prototype.runOperationWithPopup_ =
18231842
firebase.SDK_VERSION || null,
18241843
null,
18251844
null,
1826-
this['tenantId']);
1845+
this['tenantId'],
1846+
this.emulatorConfig_);
18271847
}
18281848
// The popup must have a name, otherwise when successive popups are triggered
18291849
// they will all render in the same instance and none will succeed since the

0 commit comments

Comments
 (0)