-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: skip
option for skipping by logic.
#970
Conversation
add e2e testing for @SkipThrottle() and the `skip` option
29f75b6
to
e52aa6d
Compare
for the skip option and the @SkipThrottle
e52aa6d
to
36300b9
Compare
import { ModuleMetadata, Type } from '@nestjs/common/interfaces'; | ||
|
||
export type SkipMethod = (context: ExecutionContext, ...param: any) => boolean | Promise<boolean>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can improve the ...param: any
part somehow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@micalevisk at first, I defined the Skip method like this:
export type SkipMethod = (
context: ExecutionContext,
req: Record<string, any>,
res: Record<string, any>,
) => boolean | Promise<boolean>;
but the problem is when someone want to override the handleRequest
method (for example Working with Websockets), the param now is not request and response.
So, I define the method params as ...param: any
so others can use their custom params.
`isSkip` to `shouldSkip` Co-authored-by: Micael Levi L. Cavalcante <[email protected]>
`isSkip` to `shouldSkip` Co-authored-by: Micael Levi L. Cavalcante <[email protected]>
I think rather than making this an option we pass in configuration it should be a method inside the guard that can be overwritten. Do you think you could update the code to be like that? |
I understand but I don't find that better. |
@jmcdo29 @micalevisk when can we have this feature? Are there any other way to use @SkipThrottle() conditionally? |
I still feel like a method for the class and using a new class is a cleaner approach and that I'd prefer to take that route. Maybe some method like I'm working on the next major version of this package where a few things will be changed regarding the |
Implemented in #1565 |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
There is no option to skip by logic.
ignoreUserAgents
is not safe because the user agent string can be spoofed.What is the new behavior?
Add the option
skip
to skip by logic:Override by
@SkipThrottle
Does this PR introduce a breaking change?
Other information