I will soon need to implement some kind of Multi Tenancy / Row level Authorization (And even field level?) on top of nest/crud
And i would love to collect ideas to how to tackle it in the most integrated way.
If you did anything like that i would like to hear how you did it!
I did not implement access control with nestjsx/crud. But I have a couple of thoughts. See example:
@Crud({
model: { type: User }
})
@Controller("users")
export class UsersController {
constructor(private readonly moduleRef: ModuleRef) {
}
@Override()
getMany(
@ParsedRequest() req: CrudRequest,
@User() currentUser: User
) {
const myCustomRepositoryWithAccessControl = new MyCustomRepositoryWithAccessControl(currentUser);
const someOtherDependency = this.moduleRef.get(SomeOtherDependency);
// Note: UsersService extends TypeOrmCrudService
const usersService = new UsersService(myCustomRepositoryWithAccessControl, someOtherDependency);
return usersService.getMany(req);
}
}
@Bnaya does the new @CrudAuth() feature meet your request?
Is it documented yet?
I will try to play with it
@Bnaya new @CrudAuth() decorator is here
Looks very promising, didn't had time to try i yet
I'll close the issue and reopen if i will feel something is missing
Thanks!!