Skip to content
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

UserImpl _clone incorrectly passes values resulting in UserMetadata being undefined #7057

Closed
mdedys opened this issue Feb 23, 2023 · 2 comments

Comments

@mdedys
Copy link
Contributor

mdedys commented Feb 23, 2023

[REQUIRED] Describe your environment

  • Operating System version: macOS Big Sur Version 11.7
  • Browser version: Google Chrome 109.0.5414.119
  • Firebase SDK version: v9.17.1
  • Firebase Product: auth

[REQUIRED] Describe the problem

When calling updateCurrentUser the code clones the UserImpl class but incorrectly clones the UserMetadata resulting in undefined values.

Line of code calling _clone:

return this._updateCurrentUser(user && user._clone(this));

_clone function: https://github.com/firebase/firebase-js-sdk/blob/master/packages/auth/src/core/user/user_impl.ts#L142.

The spread operator only passes keys on the UserImpl class and will not pass the Metadata properties belonging to UserMetadata. This causes https://github.com/firebase/firebase-js-sdk/blob/master/packages/auth/src/core/user/user_impl.ts#L142 to fail.

This is missed in the test because the metadata properties are never set:

Steps to reproduce:

  1. Call getAuth().updateCurrentUser(user)
  2. Once the promise completes,console.log(getAuth().currentUser) and notice that the metadata fields are not undefined

Relevant Code:

getAuth().updateCurrentUser(user).then(() => {
  console.log(getAuth().currentUser)
})

Solution:

  _clone(auth: AuthInternal): UserInternal {
    return new UserImpl({
      ...this,
      createdAt: this.metadata.creationTime,
      lastLoginAt: this.metadata.lastSignInTime,
      auth,
      stsTokenManager: this.stsTokenManager._clone()
    });
  }
@prameshj
Copy link
Contributor

Thanks for pointing this out! Are you able to send a PR with a fix, by any chance?

If not, we can add it to our list to fix.

@mdedys
Copy link
Contributor Author

mdedys commented Feb 28, 2023

Yup I can create a PR to fix the issue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants