I am using axios
to post some data to server in react native but i am having an issue my code is running well in IOS but i am having few issue with the android case. Here is my code , have a look on it.
login = () => {
const { username, password } = this.state;
let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (username == "") {
//alert("Please enter Email address");
this.setState({ email: "Please enter Email address" });
} else if (reg.test(username) === false) {
//alert("Email is Not Correct");
this.setState({ email: "Email is Not Correct" });
return false;
} else if (password == "") {
this.setState({ email: "Please enter password" });
} else {
this.openProgressbar();
axios
.post(
CONSTANT.BaseUrl + "user/do-login",
{
email: username,
password: password
}
)
.then(async (response) => {
if (response.data.type == "success") {
await AsyncStorage.setItem(
"full_name",
response.data.profile.pmeta.full_name
);
await AsyncStorage.setItem(
"user_type",
response.data.profile.pmeta.user_type
);
await AsyncStorage.setItem(
"profile_img",
response.data.profile.pmeta.profile_img
);
await AsyncStorage.setItem(
"profileBanner",
response.data.profile.pmeta.banner_img
);
await AsyncStorage.setItem(
"profileType",
response.data.type
);
await AsyncStorage.setItem(
"projectUid",
response.data.profile.umeta.id
);
await AsyncStorage.setItem(
"projectProfileId",
JSON.stringify(response.data.profile.umeta.profile_id)
);
this.setState({ isProgress: false })
RNRestart.Restart();
} else if (response.data.type == "error") {
this.setState({ isProgress: false });
alert("Please Check Your Email / Password or Check Network ");
}
})
.catch(error => {
console.log(error);
});
}
Keyboard.dismiss();
};
In the IOS case it is moving in .then
after response but in ANDROID it is going in .catch