nestjsx / crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
4.04k stars 533 forks source link

CrudAuth cross table filter #712

Closed andrei9669 closed 3 years ago

andrei9669 commented 3 years ago
Hello, I have been using this library, and loving it, for some time and finally got to implementing the auth part. but I have a problem with the auth filter. Here's the table structure. user user_clients_client client sensor
id id id id
user_id client_id
client_id

in the @CrudAuth() only thing that I get, and is usable, is id. How could I filter sensors based on what clients the user has?

I'm doing the request to the sensor table.

Char2sGu commented 3 years ago

The user you got in @CrudAuth is defined by your self, usually in an AuthGuard, so just simply ensure the user you defined on the request has the client relation loaded.

andrei9669 commented 3 years ago

oh yeah, I could just load all necessary data in AuthGuard, why didn't I think about that, thanks. altho, in authguard I get the user data from JWT token. would it be reasonable to do full user request every time someone does a request? cus most of the time, that data wouldn't be needed.

Char2sGu commented 3 years ago

oh yeah, I could just load all necessary data in AuthGuard, why didn't I think about that, thanks. altho, in authguard I get the user data from JWT token. would it be reasonable to do full user request every time someone does a request? cus most of the time, that data wouldn't be needed.

Querying the user is inevitable, but the relations of the user entity have no need to be loaded every time. The token must be validated by trying to query the user entity from the database, isn't it?

andrei9669 commented 3 years ago

well yea, right now I use a guard that checks if jwt is valid, that doesn't require querying database, but I guess In the future I will need to check if the user is banned or not, which would require querying relations. I guess I will just query the required data in its own endpoint.