diff --git a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-name.tsx b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-name.tsx index 188e5b72ad..a546cd047b 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-name.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-name.tsx @@ -24,6 +24,7 @@ const formSchema = z.object({ keyId: z.string(), name: z .string() + .trim() .transform((e) => (e === "" ? undefined : e)) .optional(), }); diff --git a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-owner-id.tsx b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-owner-id.tsx index fcf3a5211c..d635c63673 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-owner-id.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/[keyId]/settings/update-key-owner-id.tsx @@ -24,6 +24,7 @@ const formSchema = z.object({ keyId: z.string(), ownerId: z .string() + .trim() .transform((e) => (e === "" ? undefined : e)) .optional(), }); diff --git a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx index f940d81724..f6607c626c 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/keys/[keyAuthId]/new/client.tsx @@ -57,10 +57,11 @@ const formSchema = z.object({ .default(16), prefix: z .string() + .trim() .max(8, { message: "Please limit the prefix to under 8 characters." }) .optional(), - ownerId: z.string().optional(), - name: z.string().optional(), + ownerId: z.string().trim().optional(), + name: z.string().trim().optional(), metaEnabled: z.boolean().default(false), meta: z .string() diff --git a/apps/dashboard/app/(app)/apis/[apiId]/settings/update-api-name.tsx b/apps/dashboard/app/(app)/apis/[apiId]/settings/update-api-name.tsx index 3f6132f766..37d3b7b4fe 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/settings/update-api-name.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/settings/update-api-name.tsx @@ -18,7 +18,7 @@ import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; import { z } from "zod"; const formSchema = z.object({ - name: z.string(), + name: z.string().trim().min(3, "Name is required and should be at least 3 characters"), apiId: z.string(), workspaceId: z.string(), }); diff --git a/apps/dashboard/app/(app)/apis/create-api-button.tsx b/apps/dashboard/app/(app)/apis/create-api-button.tsx index 851e1e0289..5d5af2fa6e 100644 --- a/apps/dashboard/app/(app)/apis/create-api-button.tsx +++ b/apps/dashboard/app/(app)/apis/create-api-button.tsx @@ -23,7 +23,7 @@ import { useForm } from "react-hook-form"; import { z } from "zod"; const formSchema = z.object({ - name: z.string().min(2).max(50), + name: z.string().trim().min(3, "Name must be at least 3 characters long").max(50), }); export const CreateApiButton = ({ ...rest }: React.ButtonHTMLAttributes) => { diff --git a/apps/dashboard/app/(app)/authorization/roles/[roleId]/update-role.tsx b/apps/dashboard/app/(app)/authorization/roles/[roleId]/update-role.tsx index 1f134a4194..09e39a90d2 100644 --- a/apps/dashboard/app/(app)/authorization/roles/[roleId]/update-role.tsx +++ b/apps/dashboard/app/(app)/authorization/roles/[roleId]/update-role.tsx @@ -37,7 +37,13 @@ type Props = { }; const formSchema = z.object({ - name: z.string(), + name: z + .string() + .min(3) + .regex(/^[a-zA-Z0-9_:\-\.\*]+$/, { + message: + "Must be at least 3 characters long and only contain alphanumeric, colons, periods, dashes and underscores", + }), description: z.string().optional(), }); diff --git a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/create-new-override.tsx b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/create-new-override.tsx index 6f90e18c43..5ba0a17612 100644 --- a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/create-new-override.tsx +++ b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/overrides/create-new-override.tsx @@ -28,7 +28,11 @@ import { useForm } from "react-hook-form"; import { z } from "zod"; const formSchema = z.object({ - identifier: z.string().min(2).max(250), + identifier: z + .string() + .trim() + .min(3, "Name is required and should be at least 3 characters") + .max(250), limit: z.coerce.number().int().min(1).max(10_000), duration: z.coerce .number() diff --git a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/settings/update-namespace-name.tsx b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/settings/update-namespace-name.tsx index 87ec16f084..cc1b5a6f18 100644 --- a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/settings/update-namespace-name.tsx +++ b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/settings/update-namespace-name.tsx @@ -18,7 +18,15 @@ import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; import { z } from "zod"; const formSchema = z.object({ - name: z.string(), + name: z + .string() + .trim() + .min(3) + .max(50) + .regex(/^[a-zA-Z0-9_\-\.]+$/, { + message: + "Name must be 3-50 characters long and can only contain letters, numbers, underscores, hyphens, and periods.", + }), namespaceId: z.string(), workspaceId: z.string(), }); @@ -53,7 +61,7 @@ export const UpdateNamespaceName: React.FC = ({ namespace }) => { }); async function onSubmit(values: z.infer) { if (values.name === namespace.name || !values.name) { - return toast.error("Please provide a valid name before saving."); + return toast.error("Please provide a different name before saving."); } await updateName.mutateAsync(values); } diff --git a/apps/dashboard/app/(app)/ratelimits/create-namespace-button.tsx b/apps/dashboard/app/(app)/ratelimits/create-namespace-button.tsx index 3764a52a30..0f0330d73a 100644 --- a/apps/dashboard/app/(app)/ratelimits/create-namespace-button.tsx +++ b/apps/dashboard/app/(app)/ratelimits/create-namespace-button.tsx @@ -22,7 +22,15 @@ import { useForm } from "react-hook-form"; import { z } from "zod"; const formSchema = z.object({ - name: z.string().regex(/^[a-zA-Z0-9_\-\.]{3,50}$/), + name: z + .string() + .trim() + .min(1, "Name must not be empty") + .max(50, "Name must not exceed 50 characters") + .regex( + /^[a-zA-Z0-9_\-\.]+$/, + "Only alphanumeric characters, underscores, hyphens, and periods are allowed", + ), }); export const CreateNamespaceButton = ({ diff --git a/apps/dashboard/app/(app)/settings/general/update-workspace-name.tsx b/apps/dashboard/app/(app)/settings/general/update-workspace-name.tsx index 70a0be2673..50c47cb5e2 100644 --- a/apps/dashboard/app/(app)/settings/general/update-workspace-name.tsx +++ b/apps/dashboard/app/(app)/settings/general/update-workspace-name.tsx @@ -18,7 +18,7 @@ const validCharactersRegex = /^[a-zA-Z0-9-_]+$/; const formSchema = z.object({ workspaceId: z.string(), - name: z.string().min(3).regex(validCharactersRegex, { + name: z.string().trim().min(3).regex(validCharactersRegex, { message: "Workspace can only contain letters, numbers, dashes, and underscores", }), }); diff --git a/apps/dashboard/app/new/create-api.tsx b/apps/dashboard/app/new/create-api.tsx index e1180af3a2..5a8b572a0d 100644 --- a/apps/dashboard/app/new/create-api.tsx +++ b/apps/dashboard/app/new/create-api.tsx @@ -22,7 +22,7 @@ import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; import { z } from "zod"; const formSchema = z.object({ - name: z.string().min(3, "Name is required and should be at least 3 characters").max(50), + name: z.string().trim().min(3, "Name is required and should be at least 3 characters").max(50), }); type Props = { diff --git a/apps/dashboard/app/new/create-workspace.tsx b/apps/dashboard/app/new/create-workspace.tsx index 79ac2fa27d..0500e22b36 100644 --- a/apps/dashboard/app/new/create-workspace.tsx +++ b/apps/dashboard/app/new/create-workspace.tsx @@ -23,7 +23,7 @@ import { useForm } from "react-hook-form"; import { z } from "zod"; const formSchema = z.object({ - name: z.string().min(3, "Name is required and should be at least 3 characters").max(50), + name: z.string().trim().min(3, "Name is required and should be at least 3 characters").max(50), }); export const CreateWorkspace: React.FC = () => {