omar-dulaimi / trpc-shield

🛡 A tRPC tool to ease the creation of permission layer.
MIT License
402 stars 10 forks source link

Rule function return undefined value for the input param. #10

Closed benjammartin closed 1 year ago

benjammartin commented 1 year ago

Bug report

Describe the bug

Rule function return undefined for the input params. I'm using version "^0.4.0".

const isRuleName = rule<Context>()(
  async (ctx, type, path, input, rawInput, options) => {
     console.log(input) // undefined
     return true
  }
);

What I have

const permissions = shield<Context>({
  project: {
    mutation: {
      delete: isRuleName,
    },
  }
});

export const permissionsMiddleware = middleware(permissions);
export const protectedProcedure = t.procedure.use(permissionsMiddleware);

const appRouter = router({
project: router({
    delete: protectedProcedure
      .input(z.object({ id: z.string(), owner: z.string() }))
      .mutation(async ({ ctx, input }) => {
        return await prisma.project.delete({
          where: {
            id: input.id,
          },
        });
      }),
   })

Additional context

RawInput returns the content of the input.

omar-dulaimi commented 1 year ago

The value should come from tRPC itself. I'm not sure why it returns undefined here. Can you confirm that it actually return a value in other middlewares?

benjammartin commented 1 year ago

My bad! I didn't try with other middleware. This is also the case with others. I don't know why.