Using this aurelia-auth plugin together with .NET Core webAPI, I wish to return a custom error when user tries to log in with incorrect username and/or password.
WebAPI:
public HttpResponseMessage Login()
{
if (passwordValid)
{
return Request.CreateResponse(new LoginResponseViewModel { Token = token });
}
else
{
return Request.CreateResponse(HttpStatusCode.Unauthorized, "Incorrect username or password!");
}
}
Script
logIn(email, password) {
return this.auth.login(email, password)
.then(response => {
console.log("success logged " + response);
})
.catch(err => {
console.log("login failure: " + err);
});
}
- How do I access my unauthorized response custom message "Incorrect username or password" in the login function catch error?
- It seems like the aurelia-auth login function must receive a
httpStatusCode.Unauthorized
in order for it to understand that the password/username was incorrect, but that generates a401 (Unauthorized)
console error. Can I suppress this console error or perhaps return a json result which aurelia-auth understands?