mabuonomo / nestjs-guard-grpc

GrpcAuthGuard is an agnostic guard for NestJS optimized for grpc scope
11 stars 4 forks source link

get data in controller #1

Closed omidmm16 closed 4 years ago

omidmm16 commented 4 years ago

Hi Mr. Buanomo. first thanks for publishing this method. I couldn't get data and user at the same time. but I need both .

 @GrpcMethod('UserService', 'FindAll')
  findAll(@GRPCUser() user: User, data:any ,metadata: any) {
    console.log('User injected', user);
    return [];
  }
mabuonomo commented 4 years ago

hi @omidmm16 you must change the signature of your method, in your proto file, to allow the new extra field

omidmm16 commented 4 years ago

if I don't need user object, I can get data . but at the same time , I just can use one of them.

rpc SetPassword (SetPasswordInput) returns (SetPasswordRes){}

` @GrpcMethod('UserClient', 'SetPassword')

async setPassword(@GRPCUser user,data:SetPasswordInput, metadata: any): Promise { console.log('User injected', user); return { username: '', userId: '', message: password ${metadata.password} - ${metadata.repeatPassword}, statusCode: 200, }; ` what should I do?

thanks

mabuonomo commented 4 years ago

you must change your interface (and proto), for example

interface UserClient {
setPassword(user: any, data: data:SetPasswordInput, metadata: grpc.Metadata): Promise;
}
omidmm16 commented 4 years ago

in proto file signature, we should add only data message, We can't add user decorator in that,

https://github.com/nestjs/docs.nestjs.com/issues/715, https://github.com/nestjs/nest/issues/2596 Nest contributor solves this problem, but I can't do it.

in your mind, what shall we do?

thanks

mabuonomo commented 4 years ago

https://github.com/nestjs/nest/issues/4851 this link can help you? Maybe you may use also a Payload decorator

omidmm16 commented 4 years ago

I didn't see this Issue. with payload, I can get data, and decorator . thank you so much. @mabuonomo.👍 👍 👍