Storing firestore document reference in NgRx throws error

193 Views Asked by At

I am creating a project with Ionic, Angular, Firebase and NgRx and I have a problem when I try to storing document reference inside the NgRx store.

My Code:

Component

loginUser() {
  let loginFormValue = this.loginForm.value;
  this.authStore.dispatch(login({
    email: loginFormValue.email,
    password: loginFormValue.password,
    rememberMe: loginFormValue.rememberMe
  }));
}

Effect

login$ = createEffect(() => {
  return this.actions$.pipe(
    ofType(login),
    switchMap((action) => {
      return this.authenticationService.loginUserByEmail(action.email, action.password, action.rememberMe).pipe(
          map((user) => {
            return loginSucceeded({ user });
          }),
          catchError((message) => {
            return of(loginFailed({ message }));
          })
      );
    })
  );
});

Service

loginUserByEmail(email: string, password: string, rememberMe: boolean): Observable<User> {
  let persistence = rememberMe ? auth.Auth.Persistence.LOCAL : auth.Auth.Persistence.NONE;
  return new Observable( (observer: Subscriber<User>) => {
    this.angularFireAuth.setPersistence(persistence).then(() => {
      this.angularFireAuth.signInWithEmailAndPassword(email, password).then((userCredential: auth.UserCredential) => {
        this.angularFirestore.collection('users').doc(userCredential.user.uid).get().toPromise().then((doc: DocumentSnapshot<DocumentData>) => {
          let data: DocumentData = doc.data();
          if (data) {
            data.id = uid;
            data.ref = doc.ref;
          }
          observer.next(data);
          observer.complete();
         });
      });
    });
  });
}

As you can see after getting the actual data from the document I'm storing the ref on the actual data for later use. In addition, this data also contains other references to other documents.

So I am actually getting the user document from the service with all properties including the ref property but after dispatching the loginSucceeded action this error throwed in the console: Cannot read property 'ignoreUndefinedProperties' of undefined.

I didn't find solution / workaround for this.

Hope you can help me, Thanks!

0

There are 0 best solutions below