mirror of
https://github.com/formbricks/formbricks.git
synced 2026-05-08 02:43:06 -05:00
refactor: Added input validation using zod (#790)
* added input validation using zod * changed console.log to console.error * fix formatting issues --------- Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
This commit is contained in:
committed by
GitHub
parent
50d7c9666c
commit
4f4e95fecb
@@ -0,0 +1,15 @@
|
||||
import z from "zod";
|
||||
import { ValidationError } from "@formbricks/types/v1/errors";
|
||||
|
||||
type ValidationPair = [any, z.ZodSchema<any>];
|
||||
|
||||
export const validateInputs = (...pairs: ValidationPair[]): void => {
|
||||
for (const [value, schema] of pairs) {
|
||||
const inputValidation = schema.safeParse(value);
|
||||
|
||||
if (!inputValidation.success) {
|
||||
console.error(`Validation failed for ${schema}: ${inputValidation.error.message}`);
|
||||
throw new ValidationError("Validation failed");
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user