Async Await Action Creator with Redux Thunk
const BACKEND_URL = 'https://fakeserver.com/api'
export function signUpUser(email, password) {
return async (dispatch) => {
try {
const signUp = await axios.post(`${BACKEND_URL}/signup`, {
email: email,
password: password
})
// signUp.data.token <-- Access token here if the above request finished successfully.
dispatch({ type: 'SIGN_UP_SUCCESS' })
}
catch(e) {
// catch errors here
dispatch({ type: 'SIGN_UP_ERROR' })
}
}
}