From 4196dfc641bb9d43b19c0196fad9a1b2d60cfbf3 Mon Sep 17 00:00:00 2001 From: PrinOrange Date: Tue, 9 Jan 2024 16:57:42 +0800 Subject: [PATCH] Add keyword length limit to search function to prevent search overload --- pages/api/search/[keyword].ts | 4 ++++ pages/search.tsx | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pages/api/search/[keyword].ts b/pages/api/search/[keyword].ts index a62eacb..30f98ef 100644 --- a/pages/api/search/[keyword].ts +++ b/pages/api/search/[keyword].ts @@ -11,6 +11,10 @@ export default function handler(req: NextApiRequest, res: NextApiResponse ({ id: item.id, title: item.title, diff --git a/pages/search.tsx b/pages/search.tsx index 0795a7c..e65b64f 100644 --- a/pages/search.tsx +++ b/pages/search.tsx @@ -52,6 +52,10 @@ export default function SearchPage() { toast({ title: "Enter a Keyword", description: "Please enter one keyword at least." }); return; } + if (searchText.length < 10) { + toast({ title: "Keywords too short", description: "Keyword length must be at least 10." }); + return; + } querySearch.refetch(); };