feat: add Zod validation for auth endpoints
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
12
src/schemas/common.ts
Normal file
12
src/schemas/common.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { ZodSchema, ZodError } from 'zod';
|
||||
|
||||
export function parseBody<T>(schema: ZodSchema<T>, body: unknown): { data: T } | { error: string } {
|
||||
try {
|
||||
return { data: schema.parse(body) };
|
||||
} catch (e) {
|
||||
if (e instanceof ZodError) {
|
||||
return { error: e.errors.map(err => err.message).join(', ') };
|
||||
}
|
||||
return { error: 'Neplatný požadavek' };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user