Validation

From qauth-labs/qauth · View interactive version

Validation is an AI agent skill from the GitHub repository qauth-labs/qauth. Input validation and Zod v4 schemas for QAuth — standalone format validators (z.email/z.uuid/z.url, not the deprecated string-method form), schema organization, length limits, and normalize-before-validate. Use when adding or reviewing Zod schemas, route validation, or config validation.

How to use this skill

Skill file

Validation (QAuth)

Input validation for the QAuth auth-server using Zod v4. Validate at the route

boundary (fail fast), organize schemas consistently, and use the standalone Zod v4

validators. Use this skill when defining or reviewing schemas.

Zod v4 Validators

This project uses Zod v4, where many format validators are **standalone

functions, not string methods. Do not** use the deprecated string-method form.

| Use | Not |

| ----------- | -------------------- |

| z.email() | z.string().email() |

| z.uuid() | z.string().uuid() |

| z.url() | z.string().url() |

Optional error message: z.email('Invalid email format'),

z.uuid('Invalid realm ID format'), z.url('Must be a valid URL').

Also standalone in Zod v4: z.httpUrl(), z.hostname(), z.jwt(),

z.iso.date(), z.iso.datetime(), z.ipv4(), z.ipv6(), z.hex(),

z.base64(), etc. See zod.dev/api under "String formats."

If you learn another Zod v4 standalone validator, use it consistently and do not

fall back to the old string-method form.

Export the schema and its inferred type together:

export type RequestType = z.infer<typeof requestSchema>;

Schema Organization

common.ts)

strength)

Security and Best Practices

trust client input.

invalid requests return 400 before the handler runs.

happens after format validation but before storage/query.

/^[0-9a-fA-F]{64}$/, PKCE verifiers /^[A-Za-z0-9._~-]{43,128}$/).

state: z.string().max(255).optional()).

feedback for weak passwords.

Route Integration

// ✅ GOOD: Schema registered on the route (validates before the handler)
fastify.withTypeProvider<ZodTypeProvider>().post(
  '/login',
  {
    schema: {
      body: loginSchema,
      response: { 200: loginResponseSchema },
    },
  },
  async (request, reply) => {
    // request.body is typed and validated
  }
);

// ❌ BAD: Manual validation inside the handler (too late)
fastify.post('/login', async (request, reply) => {
  const body = loginSchema.parse(request.body);
});

Example Schema

export const registerSchema = z.object({
  email: z.email('Invalid email format'),
  password: z.string(),
  realmId: z.uuid('Invalid realm ID format').optional(),
});

export type RegisterRequest = z.infer<typeof registerSchema>;

Related

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.