Skip to content

Make initializeAuth() idempotent #5279

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 7 commits into from
Aug 13, 2021
Merged

Make initializeAuth() idempotent #5279

merged 7 commits into from
Aug 13, 2021

Conversation

hsubox76
Copy link
Contributor

Making all product initialize() functions idempotent.
See #5272

@changeset-bot
Copy link

changeset-bot bot commented Aug 11, 2021

⚠️ No Changeset found

Latest commit: 7970f50

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Contributor

Changeset File Check ⚠️

  • Changeset formatting error in following file:
    Package "firebase-compat-typings-test" must depend on the current version of "firebase-exp": "9.0.0-beta.8" vs "file:../../packages-exp/firebase-exp"
    Package "firebase-compat-typings-test" must depend on the current version of "firebase-exp": "9.0.0-beta.8" vs "file:../../packages-exp/firebase-exp"
    Package "firebase-compat-typings-test" must depend on the current version of "firebase-exp": "9.0.0-beta.8" vs "file:../../packages-exp/firebase-exp"
    Some packages have been changed but no changesets were found. Run `changeset add` to resolve this error.
    If this change doesn't need a release, run `changeset add --empty`.
    

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Aug 11, 2021

Binary Size Report

Affected SDKs

No changes between base commit (d46d84b) and head commit (598ec31).

Test Logs

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Aug 11, 2021

Size Analysis Report

Affected Products

  • @firebase/auth-exp

    • getAuth

      Size Table

      TypeBase (d46d84b)Head (598ec31)Diff
      size
      61.1 kB
      61.2 kB
      +90 B (+0.1%)
      size-with-ext-deps
      73.4 kB
      73.8 kB
      +421 B (+0.6%)

      External Dependency Table

      ModuleBase (d46d84b)Head (598ec31)Diff
      @firebase/util

      12 dependencies

      ErrorFactory
      FirebaseError
      base64Decode
      createSubscribe
      getModularInstance
      getUA
      isBrowserExtension
      isEmpty
      isIE
      isMobileCordova
      isReactNative
      querystring
      

      13 dependencies

      ErrorFactory
      FirebaseError
      base64Decode
      createSubscribe
      deepEqual
      getModularInstance
      getUA
      isBrowserExtension
      isEmpty
      isIE
      isMobileCordova
      isReactNative
      querystring
      

      + deepEqual

    • initializeAuth

      Size Table

      TypeBase (d46d84b)Head (598ec31)Diff
      size
      29.8 kB
      29.9 kB
      +92 B (+0.3%)
      size-with-ext-deps
      41.7 kB
      42.1 kB
      +421 B (+1.0%)

      External Dependency Table

      ModuleBase (d46d84b)Head (598ec31)Diff
      @firebase/util

      ErrorFactory
      FirebaseError
      base64Decode
      createSubscribe
      getModularInstance
      getUA
      isBrowserExtension
      isMobileCordova
      isReactNative
      querystring
      

      11 dependencies

      ErrorFactory
      FirebaseError
      base64Decode
      createSubscribe
      deepEqual
      getModularInstance
      getUA
      isBrowserExtension
      isMobileCordova
      isReactNative
      querystring
      

      + deepEqual

    • debugErrorMap

      Size Table

      TypeBase (d46d84b)Head (598ec31)Diff
      size
      40.5 kB
      40.7 kB
      +192 B (+0.5%)
      size-with-ext-deps
      52.4 kB
      52.6 kB
      +192 B (+0.4%)

@hsubox76 hsubox76 force-pushed the ch-idempotent-auth branch from 3bc3f3b to d758208 Compare August 11, 2021 22:58
@hsubox76 hsubox76 force-pushed the ch-idempotent-auth branch from d758208 to c6c254e Compare August 11, 2021 23:35
@@ -54,7 +55,12 @@ export function initializeAuth(app: FirebaseApp, deps?: Dependencies): Auth {

if (provider.isInitialized()) {
const auth = provider.getImmediate() as AuthImpl;
_fail(auth, AuthErrorCode.ALREADY_INITIALIZED);
const initialOptions = provider.getOptions() as Dependencies;
if (deepEqual(initialOptions, deps ?? {})) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we are going to use reference equality for comparing builtin objects like popupRedirectResolvers and persistences. Using deepEqual feels unnecessary.

Copy link
Contributor Author

@hsubox76 hsubox76 Aug 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was mainly using deepEqual to avoid extra lines of code, but also, while 2 of the 3 options (popupRedirectResolver and errorMap) can be compared using a simple ===, persistence can be an array, and on top of that, an array where order matters.

@Feiyang1 Feiyang1 assigned hsubox76 and unassigned Feiyang1 Aug 12, 2021
@hsubox76 hsubox76 assigned Feiyang1 and unassigned hsubox76 Aug 12, 2021
@Feiyang1 Feiyang1 assigned hsubox76 and unassigned Feiyang1 Aug 12, 2021
@Feiyang1 Feiyang1 added the v9 label Aug 12, 2021
@Feiyang1 Feiyang1 added this to the v9 GA milestone Aug 12, 2021
@hsubox76 hsubox76 merged commit 9c4aca6 into ch-idempotent Aug 13, 2021
@hsubox76 hsubox76 deleted the ch-idempotent-auth branch August 13, 2021 16:00
@firebase firebase locked and limited conversation to collaborators Sep 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants