Skip to content

[Auth] Build state listeners on streams #7430

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

Closed
wants to merge 1 commit into from

Conversation

omochi
Copy link
Contributor

@omochi omochi commented Jul 8, 2023

This PR fix #7383 which I reported.

I have confirmed that the problem has been resolved, but the overall automated testing has not yet been conducted. I will submit a pull request to share the approach to the correction promptly.

@changeset-bot
Copy link

changeset-bot bot commented Jul 8, 2023

⚠️ No Changeset found

Latest commit: 193b80a

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

@google-cla
Copy link

google-cla bot commented Jul 8, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

error?: ErrorFn,
completed?: CompleteFn
): Unsubscribe {
private createUserStateStream(
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for creating this PR and for the thorough analysis!

I wonder if a smaller scoped change like below would work (i have not tried this, just thinking out aloud). I also posted this on the issue:

private registerStateListener(
subscription: Subscription,
nextOrObserver: NextOrObserver,
error?: ErrorFn,
completed?: CompleteFn
): Unsubscribe {
if (this._deleted) {
return () => {};
}

  • let isUnsubscribed = false;
    const cb =
    typeof nextOrObserver === 'function'
    ? nextOrObserver
    : nextOrObserver.next.bind(nextOrObserver);

    const promise = this._isInitialized
    ? Promise.resolve()
    : this._initializationPromise;
    _assert(promise, this, AuthErrorCode.INTERNAL_ERROR);
    // The callback needs to be called asynchronously per the spec.
    // eslint-disable-next-line @typescript-eslint/no-floating-promises

    • promise.then(() => {if (isUnsubscribed) { return; }; cb(this.currentUser)});

    if (typeof nextOrObserver === 'function') {
    + Unsubscribe unsubscribe = subscription.addObserver(nextOrObserver, error, completed);
    + return {isUnsubscribed = true; unsubscribe();}
    } else {
    + Unsubscribe unsubscribe = subscription.addObserver(nextOrObserver);
    + return {isUnsubscribed = true; unsubscribe();}
    }
    }


Since the Observer logic is also used outside of Auth (in storage and firestore), i wonder if we can do a smaller fix. Thanks!

@omochi
Copy link
Contributor Author

omochi commented Aug 14, 2023

The issue is fixed by #7498

@omochi omochi closed this Aug 14, 2023
@firebase firebase locked and limited conversation to collaborators Sep 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Firebase Auth's onAuthStateChanged canceller does not work properly
2 participants