David AlonsoD
Convex Community14mo ago
4 replies
David Alonso

dbRules functions not being triggered

I have the following:
export const dbRules: Rules<AuthQueryCtx | AuthMutationCtx, DataModel> = {
  firestoreEdits: {
    insert: async (ctx, edit) => {
      const role = await _getExistingRoleFromUserAndOrgWorkspaceIds(ctx, {
        userId: ctx.user._id,
        workspaceId: ctx.workspace._id,
      });
      console.log("role", role);

      if (role?.role === "admin") {
        return true;
      }
      return false;
    },
...


And this:
export const zAuthenticatedMutation = zCustomMutation(
  mutationWithTriggers, // The base function we're extending
  {
    args: {
      // This type makes sure we can't just forget to pass the clerkOrgId
      // clerkOrgId: v.union(v.string(), v.null()),
      clerkOrgId: v.string(),
      userTokenIdentifier: v.optional(v.string()),
    },
    input: async (ctx, args) => {
      const { user, workspace } = await enhanceClientAuthContext(
        ctx,
        args.clerkOrgId,
        args.userTokenIdentifier
      );

      // RLS wrapper
      const safeDB: DatabaseWriter = wrapDatabaseWriter(
        { user, workspace, ...ctx },
        ctx.db,
        dbRules
      );

      return { ctx: { user, workspace }, db: safeDB, args: { ...args } };
    },
  }
);


I have a mutation that adds edits:
export const addEdit = zAuthenticatedMutation({
  args: {
    edit: zAddEditArgs,
  },
  handler: async (ctx, args) => {
...


But when i trigger it and an edit is created I don't see any logs put inside the insert function in the rules, and it doesn't seem to be used.. How is this possible?
Was this page helpful?