Skip to content

Commit

Permalink
[Auth] Update user to plumb through emulator config (#4966)
Browse files Browse the repository at this point in the history
* Update user to plumb through emulator config

* Add changeset

* Force python2 for auth test generator
  • Loading branch information
sam-gc committed Jun 14, 2021
1 parent 8250047 commit c81cf82
Show file tree
Hide file tree
Showing 4 changed files with 435 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-spiders-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/auth": patch
---

Fix bug where `linkWithPopup`, `linkWithRedirect`, `reauthenticateWithPopup`, and `reauthenticateWithRedirect` weren't correctly picking up the emulator configuration.
6 changes: 3 additions & 3 deletions packages/auth/buildtools/generate_test_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ cd "$(dirname $(dirname "$0"))"
mkdir -p generated

echo "Generating dependency file..."
python ../../node_modules/google-closure-library/closure/bin/build/depswriter.py \
python2 ../../node_modules/google-closure-library/closure/bin/build/depswriter.py \
--root_with_prefix="test ../../../../test" \
--root_with_prefix="src ../../../../src" \
> generated/deps.js

echo "Generating test HTML files..."
python ./buildtools/gen_test_html.py
python ./buildtools/gen_all_tests_js.py > generated/all_tests.js
python2 ./buildtools/gen_test_html.py
python2 ./buildtools/gen_all_tests_js.py > generated/all_tests.js

echo "Done."
28 changes: 24 additions & 4 deletions packages/auth/src/authuser.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,10 @@ fireauth.AuthUser =
// Get the client Auth endpoint used.
fireauth.constants.getEndpointConfig(fireauth.constants.clientEndpoint),
clientFullVersion);
if (appOptions['emulatorConfig']) {
this.rpcHandler_.updateEmulatorConfig(appOptions['emulatorConfig']);
/** @private {?fireauth.constants.EmulatorSettings} The emulator config */
this.emulatorConfig_ = appOptions['emulatorConfig'] || null;
if (this.emulatorConfig_) {
this.rpcHandler_.updateEmulatorConfig(this.emulatorConfig_);
}
// TODO: Consider having AuthUser take a fireauth.StsTokenManager
// instance instead of a token response but make sure lastAccessToken_ also
Expand Down Expand Up @@ -212,7 +214,7 @@ fireauth.AuthUser =
fireauth.util.isPopupRedirectSupported()) {
// Get the Auth event manager associated with this user.
this.authEventManager_ = fireauth.AuthEventManager.getManager(
this.authDomain_, this.apiKey_, this.appName_);
this.authDomain_, this.apiKey_, this.appName_, this.emulatorConfig_);
}
/** @private {!Array<!function(!fireauth.AuthUser):!goog.Promise>} The list of
* state change listeners. This is needed to make sure state changes are
Expand Down Expand Up @@ -312,7 +314,24 @@ fireauth.AuthUser.prototype.setLanguageCode = function(languageCode) {
*/
fireauth.AuthUser.prototype.setEmulatorConfig = function(emulatorConfig) {
// Update the emulator config.
this.emulatorConfig_ = emulatorConfig;
this.rpcHandler_.updateEmulatorConfig(emulatorConfig);

if (this.authEventManager_) {
// We need to get a new auth event manager keyed with the new emulator
// config.
const oldManager = this.authEventManager_;

// If authEventManager_ was previously set, we know authDomain_ is set as
// well.
this.authEventManager_ = fireauth.AuthEventManager.getManager(
/** @type {string} */ (this.authDomain_), this.apiKey_, this.appName_,
this.emulatorConfig_);
if (this.popupRedirectEnabled_) {
oldManager.unsubscribe(this);
this.authEventManager_.subscribe(this);
}
}
};


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

0 comments on commit c81cf82

Please sign in to comment.