【发布时间】:2018-07-08 12:04:04
【问题描述】:
const { payload: {loginType, email, password, notification, self} } = action;
console.log("--TRY--");
Firebase.login(loginType, { email, password })
.catch(function(result) {
const message =
result && result.message ? result.message : 'Sorry Some error occurs';
notification('error', message);
self.setState({
confirmLoading: false
});
isError = true;
})
.then(function(result) {
if (isError) {
return;
}
if (!result || result.message) {
const message =
result && result.message
? result.message
: 'Sorry Some error occurs';
notification('error', message);
self.setState({
confirmLoading: false
});
} else {
self.setState({
visible: false,
confirmLoading: false
});
console.log("--RIGHT BEFORE I CHECK AUTH STATE--");
//the following does NOT fire
firebaseAuth().onAuthStateChanged(function*(user) {
console.log("THE GENERATOR RUNS");
if (user) {
console.log(user);
yield put({
type: actions.LOGIN_SUCCESS,
token: 'secret token',
profile: 'Profile'
});
yield put(push('/dashboard'));
}
else {
yield put({ type: actions.LOGIN_ERROR });
}
});
}
}); });
嗨。我目前是第一次使用 redux saga。我一直试图在 firebaseAuth().onAuthStateChanged 监听器的回调中触发 yield。 yield 关键字在不是 ES6 生成器的函数中不起作用,所以我在回调中添加了一个星号,但现在它根本不会执行。非常感谢您对此事的任何建议。
【问题讨论】:
标签: ecmascript-6 redux firebase-authentication generator redux-saga