2
I have a login code, that when a user logs in if the data is incorrect a backend done in nodejs returns an error 401 and if everything is correct returns a status code of 200.
During the execution of the code, when the user is wrong in the data he performs the function correctly "catch", but if he puts everything correct he does not know by soul who executes the then but also the "catch".
Someone could help me with this problem?
async function handleLogin(){
await AsyncStorage.removeItem('Authorization');
await AsyncStorage.removeItem('ImAuthenticated');
await api.post('/login', {
email,
password
}, {
headers: { 'device': 'mobile' }
}).then(async(response)=>{
const { hash } = response.data;
await AsyncStorage.setItem("Authorization", hash);
await AsyncStorage.setItem("ImAuthenticated", true);
navigation.navigate('Menu');
console.log('oi');
}).catch(function (error){
if(error.response.data.showIn == "text"){
setShowInfo(true);
setEmail('');
setPass('');
this.InEmail.focus();
if(error.response.data.level == 3){
setColorInfo(false);
}else{
setColorInfo(true);
}
setInfoText(error.response.data.error);
}else{
setshowBox(true);
setEmail('');
setPass('');
this.InEmail.focus();
if(error.response.data.level == 3){
setcolorBox(false);
}else{
setcolorBox(true);
}
setboxText(error.response.data.error);
}
});
}