KennyK
Convex Communityβ€’2w agoβ€’
36 replies
Kenny

What's the correct way to double wrap

What's the correct way to double wrap the db with writers? In my case, with triggers and RLS, i get errors:

export const employeeMutation = customMutation(rawMutation, {
  args: { ...employeeArgs },
  input: async (ctx, args) => {
    if (!args.token) {
      throw new ConvexError({
        type: "invalid employee user",
        description: "No token provided",
      })
    }
    const auth = await getCurrentUserHandler(ctx, { token: args.token })
    const employee = auth?.employee

    if (!employee) {
      throw new ConvexError({
        type: "invalid employee user",
        description: "userId",
      })
    }

    return {
      ctx: {
        ...triggers.wrapDB({
          ...ctx,
          db: wrapDatabaseWriter(ctx, ctx.db, employeeRlsRules(ctx, employee), {
            defaultPolicy: "deny",
          }),
        }),
        employee,
      },
      args,
    }
  },
})


I get errors in the underlying library if I do this - I'm not sure if there's a bug in the library (rowLevelSecurity.js - this.reader is undefined), or if I'm doing this incorrectly.

(I need to wrap the rls rules before the triggers so rls rules apply in trigger functions.)
Was this page helpful?