You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had use createParamDecorator to create a custom decorator call BodyChecker , and this decorator is aim to check the request body have some filed in it , if not throw the BadRequestException , and this decorator recived two parameter
the data is the option that passed in to the BodyChecker parameter , and ctx is ExecutionContext
but this Decorator not work fine with the passport-local guard
in local.guard.ts file , I have
export class LocalGuard extends AuthGuard('local') {
// use the handleRequest method to intercept the request
canActivate(
@BodyChecker({
check: ['email', 'password'],
isJwt: false,
retCTX: true,
})
ctx,
) {
// shift to the low-level implementation of passport-local
console.log('local canActivate');
return super.canActivate(ctx);
}
// this canActivate is ref by https://docs.nestjs.com/guards#execution-context
and canActivate is hoped to received a ExecutionContext , so this BodyChecker should work fine since the ExecutionContext is
provied to the BodyChecker ,
but the final run result is the console not log the => BodyChecker called
so I don't know why this BodyChecker is not run with this canActivate function , but this BodyChecker work fine if it's not in guard ,such as in controller
the BodyChecker callback should be run , and use the context to make some check
Package
I don't know. Or some 3rd-party package
@nestjs/common
@nestjs/core
@nestjs/microservices
@nestjs/platform-express
@nestjs/platform-fastify
@nestjs/platform-socket.io
@nestjs/platform-ws
@nestjs/testing
@nestjs/websockets
Other (see below)
Other package
passport-local @nest/passport
NestJS version
9.1.5
Packages versions
[System Information]
OS Version : Linux 5.15NodeJS Version : v16.18.1YARN Version : 1.22.19
[Nest CLI]
Nest CLI Version : 9.1.5
[Nest Platform Information]
platform-express version : 9.2.0mapped-types version : 1.2.0schematics version : 9.0.3passport version : 9.0.0testing version : 9.2.0common version : 9.2.0config version : 2.2.0core version : 9.2.0jwt version : 9.0.0cli version : 9.1.5
Node.js version
v16.18.1
In which operating systems have you tested?
macOS
Windows
Linux
Other
No response
The text was updated successfully, but these errors were encountered:
How ever this problem can be easily avoid since the canActive had provied ExecutionContext , but i dont konw why this BodyChecker not work here , is there are some design purpose here ?
Is there an existing issue for this?
Current behavior
I had use createParamDecorator to create a custom decorator call BodyChecker , and this decorator is aim to check the request body have some filed in it , if not throw the BadRequestException , and this decorator recived two parameter
export const BodyChecker = createParamDecorator(
(
data: { check: string[]; isJwt: boolean; retCTX?: true | undefined },
ctx: ExecutionContext,
) => {
console.log('BodyChecker called');
the data is the option that passed in to the BodyChecker parameter , and ctx is ExecutionContext
but this Decorator not work fine with the passport-local guard
in local.guard.ts file , I have
export class LocalGuard extends AuthGuard('local') {
// use the handleRequest method to intercept the request
canActivate(
@BodyChecker({
check: ['email', 'password'],
isJwt: false,
retCTX: true,
})
ctx,
) {
// shift to the low-level implementation of passport-local
console.log('local canActivate');
return super.canActivate(ctx);
}
// this canActivate is ref by https://docs.nestjs.com/guards#execution-context
and canActivate is hoped to received a ExecutionContext , so this BodyChecker should work fine since the ExecutionContext is
provied to the BodyChecker ,
but the final run result is the console not log the => BodyChecker called
so I don't know why this BodyChecker is not run with this canActivate function , but this BodyChecker work fine if it's not in guard ,such as in controller
async login(
@BodyChecker({ check: ['email', 'password'], isJwt: false })
body: { email: string },
): Promise {
return this.auth.assignToken(body[jwtPayloadKey]);
}
Minimum reproduction code
https://github.com/kusime
Steps to reproduce
No response
Expected behavior
the BodyChecker callback should be run , and use the context to make some check
Package
@nestjs/common
@nestjs/core
@nestjs/microservices
@nestjs/platform-express
@nestjs/platform-fastify
@nestjs/platform-socket.io
@nestjs/platform-ws
@nestjs/testing
@nestjs/websockets
Other package
passport-local @nest/passport
NestJS version
9.1.5
Packages versions
Node.js version
v16.18.1
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: