我正在编写一个使用Firebase作为后端的Angular 2 + ngrx应用程序。从firebase加载实体时,特别是当从触发的NGRX效果触发结果操作时,将引发以下错误。
{code: "auth/argument-error", message: "toJSON failed: First argument must be a valid string."}
具体来说,我有一个登录页面,在用户登录后显示,其中包含计划概述。在此着陆页上,从authState
检索当前登录的用户,其ID用于启动LoadEntities操作。
this.auth.authState.subscribe(user => {
if(user) {
this.store.dispatch(new LoadEntities('plan', ref => ref.where('owner', '==', user.uid)));
} else {
this.store.dispatch(new Navigate({path: ['/login', 'authenticate']}));
}
});
我已将配置效果配置为在目标网页上启动LoadEntities
操作时触发。对正确的firebase集合执行查询,并返回实体列表。最后,启动LoadEntitiesFinish
操作,其中包含正确的实体。
@Effect() loadEntities$ = this.actions$.ofType(ActionTypes.LOAD_ENTITIES)
.map((action: LoadEntities) => action.payload)
.mergeMap(payload => {
let res: Observable<{}> = this.afs.collection<Entity>(payload.entityType, payload.query).snapshotChanges().map(angularFireAction => {
let entities: Array<Entity> = angularFireAction.map(res => {
let entity: Entity = res.payload.doc.data() as Entity;
entity.id = res.payload.doc.id;
return entity;
});
return {
entityType: payload.entityType,
entities: entities
}
}).catch((e) => {
this.logger.error(AppEffects.name, 'Could not load entities', e);
let res: Observable<any> = Observable.of(new LoadEntitiesFinish('test', null, 'Could not load entities', e));
return res;
});
return res;
})
.map((response: any) => {
let action: Action = null;
if (response.entities != null) {
action = new LoadEntitiesFinish(response.entityType, response.entities, null, null);
} else {
action = new LoadEntitiesFinish(response.entityType, null, 'Could not load entities');
}
return action;
})
.catch((e) => {
this.logger.error(AppEffects.name, 'Could not load entities', e);
let res: Observable<any> = Observable.of(new LoadEntitiesFinish('test', null, 'Could not load entities', e));
return res;
});
reducer正确创建更新状态。但是,当状态更新时,抛出上述错误。
case ActionTypes.LOAD_ENTITIES_FINISH:
let LoadEntitiesFinishEntityType = action.payload.entityType;
let LoadEntitiesFinisDelta = {}
LoadEntitiesFinisDelta[LoadEntitiesFinishEntityType + 'List'] = action.payload.entities;
return Object.assign({}, state, LoadEntitiesFinisDelta);
在用户已经过身份验证后,是否有人知道为什么会出现身份验证错误?与已启动的查询的链接是什么?
谢谢!