我在我的应用程序上实现了身份验证,问题是当我尝试在失败后登录时,例如,如果密码错误..
这是登录功能:
export const signIn = data => dispatch => {
dispatch({
type: SIGN_IN
})
fetch(API_URL+'/login', {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify(data),
}).then((response) => {
if (response.ok) {
return response.json();
} else {
throw new Error('Something went wrong');
}
}).then((responseJson) => {
dispatch({
type: SIGN_IN_SUCCESS, payload: responseJson
}),
localStorage.setItem("token", 'Bearer '+responseJson.token)
localStorage.setItem("user", JSON.stringify(responseJson.user))
})
.catch((error) => {
dispatch({
type: SIGN_IN_FAILED, payload: error
})
});
}