hyperzoneH
Convex Communityβ€’2y agoβ€’
8 replies
hyperzone

using zCustomMutation with convex-ents

How can I create a zMutation I can use from a mutation with a customCtx? I'm using this from the saas-starter:
export const mutation = customMutation(
  baseMutation,
  customCtx(async (baseCtx) => {
    return await mutationCtx(baseCtx);
  })
);

async function mutationCtx(baseCtx: BaseMutationCtx) {
  const ctx = {
    ...baseCtx,
    db: undefined,
    table: entsTableFactory(baseCtx, entDefinitions),
  };
  const identity = await ctx.auth.getUserIdentity();
  const viewer =
    identity === null
      ? null
      : await ctx.table("users").get("clerkUserId", identity.subject);
  // .get("tokenIdentifier", identity.tokenIdentifier);
  const viewerX = () => {
    if (viewer === null) {
      throw new Error("Expected authenticated viewer");
    }
    return viewer;
  };
  return { ...ctx, viewer, viewerX };
}


I don't know if it's correct but I'm trying to export this:
export const zMutation = zCustomMutation(mutation, NoOp);


but I'm getting a gigantic TS error and I'm pretty sure it's because it expects the db property on the context
Was this page helpful?