3

I have an Aurelia app using Aurelia Store. I'm having some trouble when using the @connectTo decorator in an Aurelia pipeline step.

I have added the following step to my config pipeline:

config.addPipelineStep('authorize', AuthorizeStep);

And this step looks like:

@connectTo()
export class AuthorizeStep {
  state: State;

  run(navigationInstruction, next) {
    if (navigationInstruction.getAllInstructions().find(x => x.config.isAdmin)) 
    {
      if (!this.state.user.isAdmin) {
        return next.cancel();
      }
    }

    return next();
  }
}

However, my state is always undefined. Looking at other parts of my project, I can see the state and user are being populated, but it seems like in this AuthorizeStep it doesn't seem to work.

I think this issue may be due to the fact that my AuthorizeStep doesn't have a bind lifecycle method, but if so, what can I do about this?

zewa666
  • 2,593
  • 17
  • 20
ViqMontana
  • 5,090
  • 3
  • 19
  • 54

1 Answers1

1

The maintainers of Aurelia responded (only after I raised an issue on their GitHub) here.

Basically, as the bind lifecycle does not exist within this class, the @connectTo decorator won't work. Instead, I will need to manually inject the Store and subscribing to the state.

ViqMontana
  • 5,090
  • 3
  • 19
  • 54
  • This is not an answer, you should provide the relevant information from the link to make this a "good answer". https://stackoverflow.com/help/how-to-answer – 4imble Jul 18 '18 at 15:25