OrenO
Convex Communityβ€’2y agoβ€’
15 replies
Oren

using zod schema for validation

import { z } from "zod";
import { NoOp } from "convex-helpers/server/customFunctions";
import { zCustomMutation } from "convex-helpers/server/zod";
import { mutation } from "./_generated/server";

const zMutation = zCustomMutation(mutation, NoOp);

export const emailFormSchema = z.object({
  email: z.string().email(),
});

export const add = zMutation({
  args: emailFormSchema,
  handler: async (ctx, args) => {
    await ctx.db.insert("emails", { email: args.email });
  },
});


I want to use the zod schema directly like above emailFormSchema but its giving me error;

Type 'ZodObject<{ email: ZodString; }, "strip", ZodTypeAny, { email: string; }, { email: string; }>' is not assignable to type 'void | ZodValidator | undefined'.
Was this page helpful?