macstr1k3r / trpc-nestjs-adapter

An adapter, allowing you to use TRPC inside of Nest.JS
158 stars 14 forks source link

Authrization via context #6

Open vladimirmyshkovski opened 1 year ago

vladimirmyshkovski commented 1 year ago

I have implemented NestJS connection to tRPC without your adapter, and found your solution looking for a way to authorize via context, but I see that you don't have it in your example either. Perhaps you have some ideas?

I, just like in your implementation, albeit in a different way, have access to services to call them in query and mutation, but I don't in createContext.

medv commented 1 year ago

@vladimirmyshkovski how did you go with this? Actually got to the same exact point and found this repo :sweat_smile:

edit: return req here, then you should have access to req.headers in context - or handle it further upstream through passport etc and access req.user https://github.com/macstr1k3r/trpc-nestjs-adapter/blob/aa7e5f74dde97ac1b76e361dc5f4456ad3744ef2/src/lib/build-trpc-nest-middleware.ts#L38-L41

as a sidenote, the npm package seems to have been published much more recently, at the very least there are new methods on the context object that are not passed in the above link. Any chance of getting a more recent push @macstr1k3r? Thank you for trailblazing this

macstr1k3r commented 1 year ago

@medv @vladimirmyshkovski I pushed everything I have, albeit it's not a lot.

I haven't had the need to auth so far (was handled elsewhere). I'll slowly be dipping my feet into that part in the near future and will report back.