Better permissions generation with trpc-shield #66
Replies: 1 comment
-
Hey @lewebsimple To answer your question, this generator basically uses multiple other ones and provides a basic API to interact with them. This includes generators for zod and trpc shield. So instead of installing them separately, using this generator you can use them immediately. Regarding the enhancements, while they seem quite useful, they come with their own set of challenges. Currently the shield can handle namespaced routers omar-dulaimi/trpc-shield#8 As for the second enhancement, I think it would be if it reads then build on top to avoid overwrites. Simple shield generation skipping will be available soon in a currently open PR. What do you think? |
Beta Was this translation helpful? Give feedback.
-
First off, thanks for such an amazing project !
Quick question: is there a difference between using
prisma-trpc-shield-generator
vsprisma-trpc-generator
withwithShield = true
?Also, I know this has been discussed elsewhere but I wanted to chime in on possible enhancements to the permissions generation.
Separating the generated permissions per-model
This would provide better maintainability for large-scale projects, i.e. individual files like
generated/shield/User.shield.ts
could be merged (using something like unjs/defu) and exported fromgenerated/shield/index.ts
, plus the actualshield<Context>({...})
function could be called only once from there.Preventing the permissions from being overwritten by each generation
Building upon the modular shield files described above, it becomes easier to detect if the corresponding shield file already exists and skip the generation if it's already there.
I don't know if this approach could break or complicate the typing, but it would certainly be an elegant and maintainable solution to permissions generation.
Beta Was this translation helpful? Give feedback.
All reactions