错误类型:无法添加属性0,对象不可扩展(ngrx / firebase / angularfire)
我知道这个问题已经在Stackoverflow上进行了多次报道,但是没有回答这些问题。我已经阅读了所有评论,但是我仍然不明白它与我的代码有何关系。
我正在尝试使用AngularFire中的setDoc
添加一个用户文档:
firebase.service.ts
public addUserDocument(userId: string, data: UserDocument) {
const usersRef = doc(this._fireStore, 'users', userId);
return from(setDoc(usersRef, {...data}));
}
我在我的ngrx效果中正在调用adduserDocument
。
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 });
尝试注册时,我会得到以下供应商错误
:
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)
但是,如果我在authsignup $
的内部执行所有操作效果和管道响应,它可以正常工作:
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}
);
供应商软件包有问题,还是我的代码有问题?
非常感谢您的帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论