Example code:
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,
}
},
})
Any time I call e.g. ctx.db.patch or ctx.db.get inside a function wrapped by employeeMutation, I get the following error :
TypeError: Cannot read properties of undefined (reading 'get')
Object.get node_modules/convex-helpers/server/rowLevelSecurity.js:245:28
Its important than RLS policies are adhered to inside the trigger, which is why I haven't wrapped a custom mutation in a trigger wrapper, then wrapped this in am RLS wrapper.
As recommended in the trigger docs, the following works, BUT does not adhere to RLS policies, which is the issue:
const mutationWithTriggers = customMutation(
rawMutation,
customCtx(triggers.wrapDB),
)
export const employeeMutation = customMutation(mutationWithTriggers, {
...
})
Example code:
Any time I call e.g. ctx.db.patch or ctx.db.get inside a function wrapped by employeeMutation, I get the following error :
Its important than RLS policies are adhered to inside the trigger, which is why I haven't wrapped a custom mutation in a trigger wrapper, then wrapped this in am RLS wrapper.
As recommended in the trigger docs, the following works, BUT does not adhere to RLS policies, which is the issue: