【发布时间】:2018-01-02 10:14:25
【问题描述】:
我正在尝试在我的 react redux 应用程序中使用 firebase 进行身份验证。 我想在成功登录时将用户重定向到下一页,但在提交登录表单时出现错误
错误
Cannot read property 'then' of undefined
在 LoginForm 中处理提交功能
handleFormSubmit(event) {
event.preventDefault();
if (this.props.email !== '' && this.props.password !== '') {
this.props.loginUser(this.props.email, this.props.password)
.then(() => {
this.context.router.push('/posts');
});
} else {
console.log('empty');
}
}
动作创建者
export function loginUser(email, password) {
return (dispatch) => {
dispatch({ type: LOGIN_USER });
firebase.auth().signInWithEmailAndPassword(email, password)
.then(user => loginUserSuccess(dispatch, user))
.catch(() => {
console.log('failed to sign in');
return;
});
};
}
export function loginUserSuccess(dispatch, user) {
dispatch({
type: LOGIN_USER_SUCCESS,
payload: user
});
}
如果我从句柄提交函数中删除 then 验证有效,但我不知道如何将用户重定向到下一页?
【问题讨论】:
标签: javascript reactjs firebase react-router react-redux