MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / createSchema

Function createSchema

apps/webapp/app/routes/confirm-basic-details.tsx:28–67  ·  view source on GitHub ↗
(
  constraints: {
    isEmailUnique?: (email: string) => Promise<boolean>;
  } = {}
)

Source from the content-addressed store, hash-verified

26import { rootPath } from "~/utils/pathBuilder";
27
28function createSchema(
29 constraints: {
30 isEmailUnique?: (email: string) => Promise<boolean>;
31 } = {}
32) {
33 return z
34 .object({
35 name: z.string().min(3, "Your name must be at least 3 characters").max(50),
36 email: z
37 .string()
38 .email()
39 .superRefine((email, ctx) => {
40 if (constraints.isEmailUnique === undefined) {
41 //client-side validation skips this
42 ctx.addIssue({
43 code: z.ZodIssueCode.custom,
44 message: conform.VALIDATION_UNDEFINED,
45 });
46 } else {
47 // Tell zod this is an async validation by returning the promise
48 return constraints.isEmailUnique(email).then((isUnique) => {
49 if (isUnique) {
50 return;
51 }
52
53 ctx.addIssue({
54 code: z.ZodIssueCode.custom,
55 message: "Email is already being used by a different account",
56 });
57 });
58 }
59 }),
60 confirmEmail: z.string(),
61 referralSource: z.string().optional(),
62 })
63 .refine((value) => value.email === value.confirmEmail, {
64 message: "Emails must match",
65 path: ["confirmEmail"],
66 });
67}
68
69export const action: ActionFunction = async ({ request }) => {
70 const userId = await requireUserId(request);

Callers 2

actionFunction · 0.70
onValidateFunction · 0.70

Calls 3

maxMethod · 0.80
minMethod · 0.80
thenMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…