Hello, I am currently using a function that is quite similar to this one with some minor tweaks here.
However, I have encountered an issue when trying to log in to my REST API. Even if I input the incorrect username or password, it still authenticates me and logs me in.
The problem lies in the fact that it should trigger the catch
block when the credentials are wrong, but for some reason, it fails to do so. This was a previous issue that I managed to resolve, but now I am struggling to understand why it is happening again.
In my Login.vue file:
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 in my backend-service.js file:
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);
});
}
With the line return result;
, even if the credentials are incorrect, the output shows:
{ error: 'Not connected.' }
Even adding return;
to return false
does not prevent the authentication process.