Consider custom path option for tRPC Shield
okeeffed opened this issue · comments
Problem
There is currently an option to generate custom shield definitions to <output>/shield/shield.ts
, where the exported permissions
variable is imported into <output>/routers/helpers/createRouter.ts
.
This is great, but re-generating from Prisma will result in changes to <output>/shield/shield.ts
being overridden back to the base generation. If you set withShield
to false, then the file is removed on the next generation as the path <output>
looks to be removed.
This is problematic for CI builds that re-generate Prisma definitions at build time.
Suggested solution
Add a shieldPath
option that operates similar to contextPath
and trpcOptionsPath
to allow a custom path to the shield file permissions. This would allow us to generate the initial file at another path so that any changes can be committed and not overridden.
Alternatives
Alternatively, we could (if it is possible) enable it so that the designated output
path is not removed on re-generation but only the subfolders (with overrides as well). This would enable me to safely commit the shield
folder to Git, remove the withShield
option and not have the file overridden during generation at CI.
The other current alternative is what I am doing now: committing the files to Git and then diff'ing future generations, but it also means no generation during CI.
Additional context
N/A
For version 1.4.1 I can set
withShield = "../src/server/api/permissions"
where I have
import { rule, shield } from "trpc-shield";
import { type Context } from "./contextType";
const isAuthenticated = rule<Context>()((ctx) => !!ctx.session);
export const permissions = shield<Context>(
{
query: {},
mutation: {},
},
{ fallbackRule: isAuthenticated }
);
and that is solving this problem for me. Hope this helps!!!
Trueeeeee @coreyrr ! I did not read the README API correctly 🤦
Next time I should at least check the source code first! Thank youuuuuu ❤️