fixed schema

This commit is contained in:
Omer Sabic 2024-06-07 20:35:20 +02:00
parent d3cce3f8cb
commit ccb7bf3f80
2 changed files with 2 additions and 10 deletions

View File

@ -26,7 +26,7 @@ export const actions = {
default: async (event) => { default: async (event) => {
const form = await superValidate(event, zod(schema)); const form = await superValidate(event, zod(schema));
if (!form.valid) { if (!form.valid) {
console.log(form); console.log("form invalid")
return fail(400, { return fail(400, {
form form
}); });

View File

@ -1,20 +1,12 @@
import { z } from "zod"; import { z } from "zod";
const domain_regex = /^[a-z0-9\.\-]*$/;
/**
* @param {string} key
* @returns {boolean}
*/
const isValidDomain = key => key === null || domain_regex.test(key);
export const schema = z.object({ export const schema = z.object({
id: z.string(), id: z.string(),
name: z.string().min(4).max(32), name: z.string().min(4).max(32),
primary_color_hex: z.string().length(7), primary_color_hex: z.string().length(7),
secondary_color_hex: z.string().length(7), secondary_color_hex: z.string().length(7),
text_color_hex: z.string().length(7), text_color_hex: z.string().length(7),
domain: z.string().refine(isValidDomain, { domain: z.string().refine((key) => key === null || /^[a-z0-9\.\-]*$/.test(key), {
message: "Invalid domain" message: "Invalid domain"
}).nullable(), }).nullable(),
use_freebie: z.boolean().default(false), use_freebie: z.boolean().default(false),