Skip to content

[Auth] Update user to plumb through emulator config #4966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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
Loading