Hello I'm using a function very similar to this one, with little changes https://play.nativescript.org/?template=play-vue&id=HdDm9M&v=786
When I login to my rest api, if I put in the wrong username or password, it always returns true (by logging me in).
It should execute the catch block when my username or password is wrong but it does not do that. I had this issue before and fixed it but now I can't figure out why this happens.
In my Login.vue
login() {
this.$backend
.login(this.user)
.then(() => {
// if login success then save login and password in local storage
appSettings.setString("username", this.user.username);
appSettings.setString("password", this.user.password);
this.$store.commit('setActualPage', 'Main');
this.processing = false;
this.$navigateTo(Main, { clearHistory: true });
})
.catch(() => {
this.processing = false;
this.alert(
"Username or password are not correct."
);
});
},
and my backend-service.js
login(user) {
return httpModule.request({
url: "MYRESTAPIURL",
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"username": user.username,
"password": user.password,
"apikey": "814973593645gg6db8ca6983789f"
}
}).then((response) => {
let result = response.content.toJSON();
return result;
//console.log(result.premiumdays)
}, (e) => {
console.log(e);
});
}
This return result; gives the output below if it's the wrong user or password:
{ error: 'Not connected.' }
Even if I put return; to return false it logs me in.