'ERROR TypeError: Cannot add property 0, object is not extensible (NgRx / FireBase / AngularFire)

I am aware that this issue has been reported several times on StackOverflow, but none of the questions has been answered. I have read all of the comments, but I can still not understand how it relates to my code.

I am trying to add a user document to Firestore using setDoc from AngularFire:

firebase.service.ts

  public addUserDocument(userId: string, data: UserDocument) {
   const usersRef = doc(this._fireStore, 'users', userId);
    return from(setDoc(usersRef, {...data}));
  }

I am calling the addUserDocument in my NgRx effects.

auth.effects.ts

  authSignUp$ = createEffect(
    () =>
      this._actions$.pipe(
        ofType(authSignUp),
        switchMap((formData) =>
          this._firebaseService.signUp(formData.email, formData.password).pipe(
            map(response => ({
              user: response.user,
              displayName: formData.displayName
            }))
          )
        ),
        map(data =>  authSignUpSuccess(data))
      ),
  );

  authSignUpSuccess$ = createEffect(() =>
    this._actions$.pipe(
      ofType(authSignUpSuccess),
      switchMap(data => {
        console.log("adding doc")
        return this._firebaseService.addUserDocument(data.user.uid, {
          metaData: {
            isOnboarded: false
          }
        });
      }),
    ), { dispatch: false });

When trying to sign-up I get the following vendor error:

ERROR TypeError: Cannot add property 0, object is not extensible
    at Array.push (<anonymous>)
    at ObserverProxy.subscribe (vendor.js:62785:20)
    at AuthImpl.registerStateListener (vendor.js:6441:27)
    at AuthImpl.onIdTokenChanged (vendor.js:6294:17)
    at AuthInterop.addAuthTokenListener (vendor.js:15609:35)
    at o (vendor.js:32582:87)
    at vendor.js:32585:24
    at Provider.onInit (vendor.js:127253:7)
    at J.start (vendor.js:32585:12)
    at new $a (vendor.js:51436:295)

However, if I do everything inside of the authSignUp$ effect and pipe the response, it works just fine:

  authSignUp$ = createEffect(
    () => 
    this._actions$.pipe(
      ofType(authSignUp),
      switchMap(
        formData => this._firebaseService.signUp(formData.email, formData.password).pipe(
          tap((response) => this._firebaseService.addUserDocument(response.user.uid, {
            metaData: {
              isOnboarded: false
            }
          }
            ))
        )
      )
    ),
    {dispatch: false}
  );

Is there something wrong with the vendor package, or is there something wrong with my code?

Thank you very much for your help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source