2

How can I access a route or group metadata from within an interceptor?

I would like to add a @public() to a route like:

@app.Route("/user/find/:id")
@public()
getUser(String id) => {"name": "User", "login": "user"};

And create an interceptor that blocks the access to the routes that do not have the public metadata and there is no logged user. Is this possible?

@app.Interceptor(r'/admin/.*')
adminFilter() {
  if (app.request.session["username"] != null || CURRENT_ROUTE_HAS_PUBLIC_METADATA) {
    return app.chain.next();
  } else {
    return app.chain.abort(HttpStatus.UNAUTHORIZED);
    //or app.chain.redirect("/login.html");
  }
}
Jonathan
  • 4,724
  • 7
  • 45
  • 65

1 Answers1

2

I added an option to the package that exposes the method mirror and group mirror. With that, I could retrieve all methods that are public with their exposed route pattern.

Jonathan
  • 4,724
  • 7
  • 45
  • 65