From faa5082090cead23e84c43a1bec2a4beee280e64 Mon Sep 17 00:00:00 2001 From: pheralb Date: Mon, 1 Apr 2024 14:54:11 +0100 Subject: [PATCH] Update create & update url schema --- src/server/schemas/index.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/server/schemas/index.ts b/src/server/schemas/index.ts index 9b9d3a7..aaad1a4 100644 --- a/src/server/schemas/index.ts +++ b/src/server/schemas/index.ts @@ -15,6 +15,10 @@ export const CreateLinkSchema = z.object({ .url({ message: "Please enter a valid URL. Include http:// or https://", }) + .regex(/^(?!.*(?:http|https):\/\/(?:slug|slugr)\.vercel\.app).*$/, { + message: "You cannot redirect to the Slug url.", + }) + // not contain any blank spaces .regex(/^\S+$/, { message: "URL must not contain any blank spaces.", }), @@ -39,7 +43,16 @@ export const CreateLinkSchema = z.object({ export const EditLinkSchema = z.object({ id: z.string(), - url: z.string().min(1, { message: "URL is required." }), + url: z + .string() + .min(1, { message: "URL is required." }) + .regex(/^(?!.*(?:http|https):\/\/(?:slug|slugr)\.vercel\.app).*$/, { + message: "You cannot redirect to the Slug url.", + }) + // not contain any blank spaces + .regex(/^\S+$/, { + message: "URL must not contain any blank spaces.", + }), slug: z .string() .min(1, { message: "Short link is required." })