当我使用此效果注销时,我的oauth设置存在问题:
@Effect()
logout: Observable<Action> = this.actions.ofType(UserActions.LOGOUT)
.switchMap(() => Observable.of(this.afAuth.auth.signOut()))
.map(() => new UserActions.GetUser())
.catch(err => Observable.of(new UserActions.AuthError({error: err.message})));
一切正常, UserActions.GetUser()
正在被召唤 . 现在,如果我尝试使用此效果和此firebase auth函数登录:
@Effect()
googleLogin: Observable<Action> = this.actions.ofType(UserActions.GOOGLE_LOGIN)
.switchMap(() => Observable.fromPromise(this.loginWithGoogle()))
.map(() => new UserActions.GetUser())
.catch(err => Observable.of(new UserActions.AuthError({error: err.message})));
private loginWithGoogle() {
return this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider());
}
新的 UserActions.GetUser()
被调用,我可以在Redux DevTools中看到它,但实际效果没有被调用,我放了很多console.log 's in there to see if i did something wrong in the function, but it isn'来调用 GetUser
,而且我也有 catch
,但是这也没有触发 .
在这种情况下是否存在firebase的问题或者我是愚蠢的?
操作:
获得用户效果:
@Effect()
getUser: Observable<Action> = this.actions.ofType(UserActions.GET_USER)
.switchMap(() => {
console.log('test'); // <-- Not called
return this.afAuth.authState;
})
.map(()=> {
return new UserActions.Authenticated();
});
** EDIT 1
我做了一个新的观察:当没有互联网连接,所以firebase从本地加载,它实际上工作,不知何故连接到firebase数据库的问题
3 回答
尝试使用这个:
为此,exhaustMap和switchMap之间有一点区别 . 如果你成功的话,请告诉我 .
你能试试这个吗?在我看来这可能会有所帮助 .
我遇到了类似的问题,我认为效果没有被调用,因为在你的
getUser
效果中你没有实现catch
块如果效果会抛出任何错误,所以理想情况下在这种情况下如果一个效果出错而且它没有调用't have any catch mechanism the effect won't进一步的行动 .