crud icon indicating copy to clipboard operation
crud copied to clipboard

CrudAuth applying to only particular routes

Open bschulte opened this issue 4 years ago • 3 comments

Is there an easy way to only have the filter function used in CrudAuth apply to only certain routes? For instance I ran into an error when I wanted to have the filter apply to just the getOneBase route, but it was applying to createOneBase as well and user was undefined causing an error.

bschulte avatar Jul 21 '20 02:07 bschulte

The simplest way I can think of is to just override the function and decorate it, e.g.

@CrudAuth({your: options})
getOne (req: CrudRequest): Promise<School> {
  return super.getOne(req);
}

nick-lehmann avatar Aug 12 '20 21:08 nick-lehmann

If I do that suggestion 👆 I get “Unable to resolve signature of class decorator when called as an expression” in regards to the @CrudAuth decorating being there inside the class, rather than above the class.

There is a beautiful way to apply a decorator to a specific route, documented here: https://github.com/nestjsx/crud/wiki/Controllers#routes but the @CrudAuth decorator is not applying. No errors, just doesn't do the filter. Only seems to work when applied above the class to all routes.

Any suggestions?

kevinsproles avatar Oct 23 '20 17:10 kevinsproles

Same here - its not possible to use @CrudAuth as a decorator for a route. It's only working for the whole Controller.

adshrc avatar Jun 29 '22 10:06 adshrc