0

Not sure how isEmail is intended to be used?

.mutation("add", {
    input: z.object({
      email: z.string().min(1).isEmail(), <----- ? this doesn't seem to work / throws an error
    }),
    async resolve({ ctx, input }) {
      let user = await prisma.subscriber.create({
        data: {
          email: input.email,
        },
      });

      return { email: input.email };
    },
  });

I thought isEmail would simply validate the input before getting it through the schema, but this doesn't seem to be the idea?

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
antonwilhelm
  • 5,768
  • 4
  • 19
  • 45

1 Answers1

1

Just to focus in on why .isEmail is not working, I believe the correct refinement is just email. The email refinement will validate that the string is an email, so I don't think you need the min(1) check as email is a stricter validation.

z.object({
  input: z.string().email(),
})
Souperman
  • 5,057
  • 1
  • 14
  • 39