PipelineStep with HttpClient-Request

I’m trying to setup a pipeline step “role management” where I need to request the web service. Now my problem is, that the http-request is asynchonious and so the redirect is never triggered correctly.

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();
}

Can someone show me how to solve that?

Can you try addng return before this.roleService...

1 Like

good hint.
I got it working by changing the method to an async-method:

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();
}

Yes, code is nicer using async/await. Without using it, you have to add return ... like my suggestion above to make it work.

ok. Thank you very much