Injecting middleware and/or permissions #30
-
Hello! If using withMiddleware=true and withShield=true, how does one use permissions besides those automatically created? helpers/createRouter.ts looks like this:
Permissions is imported from where they are auto-generated, and of course the auto-generated ones cannot be used as-is (as they are completely permissive). Where can I inject my own permissions object or otherwise achieve using my own middleware while still using the auto-generated appRouter? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @kristinlindquist , thank you for using this library. Custom rules can be defined easily as described on the tRPC Shield README. Also, since Prisma tRPC Shield Generator and any Prisma generator in general aim to always be consistent with the Prisma schema, this means the generated files will always be overwritten. Now, as for defining custom rules through generation, this currently isn't supported. Maybe we can read comments from the Prisma schema. But as you know the schema does not mention the CRUD operations; just the models and the fields. So, the other way might be to 1st generate the default object, then pass it as an option to the generator again after the user has modified it with the proper rules name. Of course, this isn't supported yet. |
Beta Was this translation helpful? Give feedback.
Hey @kristinlindquist , thank you for using this library.
Custom rules can be defined easily as described on the tRPC Shield README.
Also, since Prisma tRPC Shield Generator and any Prisma generator in general aim to always be consistent with the Prisma schema, this means the generated files will always be overwritten.
Now, as for defining custom rules through generation, this currently isn't supported.
Maybe we can read comments from the Prisma schema. But as you know the schema does not mention the CRUD operations; just the models and the fields.
So, the other way might be to 1st generate the default object, then pass it as an option to the generator again after the user has modified it…