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." })