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

Handle Observers in onAuthStateChanged #23

Open
wSedlacek opened this issue Jun 19, 2020 · 0 comments
Open

Handle Observers in onAuthStateChanged #23

wSedlacek opened this issue Jun 19, 2020 · 0 comments

Comments

@wSedlacek
Copy link
Collaborator

In this section

mockbase/auth/auth.ts

Lines 67 to 78 in 61b9467

onAuthStateChanged(
nextOrObserver: AuthStateChangeListener,
error?: (a: firebase.auth.Error) => void,
completed?: firebase.Unsubscribe
): firebase.Unsubscribe {
this.authStateEvents.add(nextOrObserver);
nextOrObserver(this.currentUser);
return () => {
this.authStateEvents.delete(nextOrObserver);
};
}

When used with

  public readonly authState = new Observable<User | null>(
    this.auth.onAuthStateChanged.bind(this.auth)
  );

as done in
https://github.com/angular/angularfire/blob/2de8501d10add9e575885db9f44b8098e5857929/src/auth/auth.ts#L66

throws the following error.

TypeError: nextOrObserver is not a function

It should be noted that nextOrObserver is a SwitchMapSubscriber when this error occurs.

Reference:
https://github.com/ReactiveX/rxjs/blob/b8c2a52bf78e855dfe48e3620b7ee2fee05ec120/src/internal/operators/switchMap.ts#L109

Simply checking typeof should allow us to determine if nextOrObserver is next or observer
observer seem to be expecting you to call nest() on them with the user.

Here is the firebase implementation of this function for additional reference
https://github.com/firebase/firebase-js-sdk/blob/35bc0a2eea98d9796023f15cd5783700d45ccc4d/packages/auth/src/auth.js#L1442-L1472

@wSedlacek wSedlacek self-assigned this Jun 19, 2020
@wSedlacek wSedlacek removed their assignment Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant