Aurelia 身份验证 - 自定义响应消息 - 控制台错误
Aurelia auth - custom response message - console error
将 this aurelia-auth 插件与 .NET Core webAPI 一起使用,我希望 return 当用户尝试使用不正确的用户名 and/or 密码登录时出现自定义错误。
WebAPI:
public HttpResponseMessage Login()
{
if (passwordValid)
{
return Request.CreateResponse(new LoginResponseViewModel { Token = token });
}
else
{
return Request.CreateResponse(HttpStatusCode.Unauthorized, "Incorrect username or password!");
}
}
脚本
logIn(email, password) {
return this.auth.login(email, password)
.then(response => {
console.log("success logged " + response);
})
.catch(err => {
console.log("login failure: " + err);
});
}
- 如何在登录功能捕获错误中访问我未经授权的响应自定义消息"Incorrect username or password"?
- aurelia-auth 登录功能似乎必须接收
httpStatusCode.Unauthorized
才能理解 password/username 不正确,但会产生 401 (Unauthorized)
控制台错误。我可以抑制这个控制台错误或者 return aurelia-auth 理解的 json 结果吗?
1。如何访问自定义未授权响应消息
服务器响应:
return Request.CreateResponse(HttpStatusCode.Unauthorized, "My message");
客户:
return this.auth.login(email, password)
.then(response => {
console.log("success logged " + response);
})
.catch(error => error.json().then(serverError =>
console.log(serverError) //My message
));
2。抑制控制台错误或 return aurelia-auth 理解的 json 结果
在当前版本的 aurelia-auth 中不可能 return aurelia-auth 理解的 json 结果。
我决定更换现在的 aurelia-auth package with aurelia-authentication。
Aurelia-authentication is fork of aurelia-auth which itself is a port of the great Satellizer library。使用新包我现在可以做更多,(刷新令牌,return 来自服务器的自定义消息等)..
将 this aurelia-auth 插件与 .NET Core webAPI 一起使用,我希望 return 当用户尝试使用不正确的用户名 and/or 密码登录时出现自定义错误。
WebAPI:
public HttpResponseMessage Login()
{
if (passwordValid)
{
return Request.CreateResponse(new LoginResponseViewModel { Token = token });
}
else
{
return Request.CreateResponse(HttpStatusCode.Unauthorized, "Incorrect username or password!");
}
}
脚本
logIn(email, password) {
return this.auth.login(email, password)
.then(response => {
console.log("success logged " + response);
})
.catch(err => {
console.log("login failure: " + err);
});
}
- 如何在登录功能捕获错误中访问我未经授权的响应自定义消息"Incorrect username or password"?
- aurelia-auth 登录功能似乎必须接收
httpStatusCode.Unauthorized
才能理解 password/username 不正确,但会产生401 (Unauthorized)
控制台错误。我可以抑制这个控制台错误或者 return aurelia-auth 理解的 json 结果吗?
1。如何访问自定义未授权响应消息
服务器响应:
return Request.CreateResponse(HttpStatusCode.Unauthorized, "My message");
客户:
return this.auth.login(email, password)
.then(response => {
console.log("success logged " + response);
})
.catch(error => error.json().then(serverError =>
console.log(serverError) //My message
));
2。抑制控制台错误或 return aurelia-auth 理解的 json 结果
在当前版本的 aurelia-auth 中不可能 return aurelia-auth 理解的 json 结果。
我决定更换现在的 aurelia-auth package with aurelia-authentication。
Aurelia-authentication is fork of aurelia-auth which itself is a port of the great Satellizer library。使用新包我现在可以做更多,(刷新令牌,return 来自服务器的自定义消息等)..