Typescript Aurelia-在管道步骤中请求web服务
我正在尝试设置一个管道步骤“角色管理”,在这里我需要请求web服务。现在我的问题是,http请求是异步的,因此重定向从未正确触发Typescript Aurelia-在管道步骤中请求web服务,typescript,httpclient,aurelia,Typescript,Httpclient,Aurelia,我正在尝试设置一个管道步骤“角色管理”,在这里我需要请求web服务。现在我的问题是,http请求是异步的,因此重定向从未正确触发 run(routingContext, next){ if (routingContext.getAllInstructions().some(i => i.config.permission)) { let permission = routingContext.getAllInstructions()[0].con
run(routingContext, next){
if (routingContext.getAllInstructions().some(i => i.config.permission)) {
let permission = routingContext.getAllInstructions()[0].config.permission;
this.roleService.userIsAllowedTo(permission)
.then(boolResponse => {
if(boolResponse){
return next();
}else{
return next.cancel(new Redirect("/"));
}
});
}
return next();
}
有人能告诉我如何解决这个问题吗?只要从run()返回承诺就行了
从run()返回承诺
多谢各位。我现在可以通过将该方法更改为异步方法来解决该问题:
async run(routingContext, next){
if (routingContext.getAllInstructions().some(i => i.config.permission)) {
let permission = routingContext.getAllInstructions()[0].config.permission;
let isallowed = await this.roleService.userIsAllowedTo(permission);
if(isallowed){
return next();
}else{
return next.cancel();
}
}
return next();
}
多谢各位。我现在可以通过将该方法更改为异步方法来解决该问题:
async run(routingContext, next){
if (routingContext.getAllInstructions().some(i => i.config.permission)) {
let permission = routingContext.getAllInstructions()[0].config.permission;
let isallowed = await this.roleService.userIsAllowedTo(permission);
if(isallowed){
return next();
}else{
return next.cancel();
}
}
return next();
}