I'm trying to use firebase for authentication in my react redux app. I want to redirect user to next page on successful login but I'm getting the error when I submit the login form
Error
Cannot read property 'then' of undefined
Handle Submit function in 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');
}
}
Action Creator
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
});
}
The authentication works if I remove the then from handle submit function but I don't know how to redirect user to next page ?