Answer the question
In order to leave comments, you need to log in
How to call action when needed?
There is an action login that is called on onSumbit:
const onSubmit = data => {
console.log(data);
dispatch(login(data));
}
export function login(data) {
return dispatch => {
return axios.post('http://localhost:5000/api/auth/login', data).then(res => {
console.log(res)
const token = res.data.token;
localStorage.removeItem('jwtToken');
localStorage.setItem('jwtToken', token);
dispatch(loadUser(token));
})
.catch(function (error) {
dispatch(returnErrors(error.message, error.status, "signIn"))
});
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question