Avallone-io / rls

Row level security (RLS) package for TypeORM and NestJS
ISC License
61 stars 12 forks source link

Escaping Request.SCOPE with CLS (AsyncLocalStorage) #218

Open nugmanoff opened 1 year ago

nugmanoff commented 1 year ago

Hey! Thanks so much for this library, it is so useful and I wonder why it is not more widely used, due to the importance of the problem it solves.

One obvious thing where it could become even better is escaping the request-scoped-ness altogether. Which seems to be pretty much possible with things like CLS (continuation-local storage), which leverages NodeJS Async Local Storage.

I think it would be quite beneficial in general to add support for integration with CLS libs like nestjs-cls, which would allow less-constrained usage for everyone.

It seems like integration should be quite straightforward, I forked this library and tried to give it a shot following nest-js cls docs by simply swapping the request object with CLS_REQ thus lifting the Request.SCOPE constraint.

Although it looks like it should be enough, for some reason I can't get TENANT_CONNECTION to be injected in derived features like repositories. To be honest I am quite new to Nest.js and I am not yet that comfortable with Injection Scopes, Dynamic Modules & etc. So probably it is something rather straightforward, just my inexperience is blocking things here.

Would love to hear your thoughts on this!

stelescuraul commented 1 year ago

Hi @nugmanoff . Thanks for the suggestion. I am not familiar with CLS so let me take a look on this first and then i`ll get back to you with more info.

adcsm2 commented 8 months ago

Hi there,

I'm also experiencing a similar issue and I'm really interested in this feature. I wanted to know if there is any progress or updates on this. I'd appreciate any information on the status of this issue and if there's a timeline for implementing this feature.

Thanks!

umussetu commented 3 weeks ago

+1, would be super cool to have that. @nugmanoff did you find the solution?

nugmanoff commented 2 weeks ago

Hey @umussetu I've given up on TypeORM and RLS altogether and just went with more straightforward approach by passing tenantId everywhere I need and including it in WHERE clause in queries. More typing indeed, but less magic, thus more clarity.