⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
added username check
Daniel742e17351e46
diff --git a/lib/api/controllers/users/updateUser.ts b/lib/api/controllers/users/updateUser.tsindex 064dd84e..cdf62607 100644--- a/lib/api/controllers/users/updateUser.ts+++ b/lib/api/controllers/users/updateUser.ts@@ -20,6 +20,15 @@ export default async function updateUser(status: 400,};+ const checkUsername = RegExp("^[a-z0-9_-]{3,31}$");++ if (!checkUsername.test(user.username))+ return {+ response:+ "Username has to be between 3-30 characters, no spaces and special characters are allowed.",+ status: 400,+ };+const userIsTaken = await prisma.user.findFirst({where: {id: { not: sessionUser.id },diff --git a/pages/api/auth/register.ts b/pages/api/auth/register.tsindex 9e91beee..44406ee6 100644--- a/pages/api/auth/register.ts+++ b/pages/api/auth/register.ts@@ -52,6 +52,14 @@ export default async function Index(},});+ const checkUsername = RegExp("^[a-z0-9_-]{3,31}$");++ if (!checkUsername.test(body.username))+ return res.status(400).json({+ response:+ "Username has to be between 3-30 characters, no spaces and special characters are allowed.",+ });+const checkIfUserExists = await prisma.user.findFirst({where: emailEnabled? {@@ -84,8 +92,10 @@ export default async function Index(},});- res.status(201).json({ response: "User successfully created." });+ return res.status(201).json({ response: "User successfully created." });} else if (checkIfUserExists) {- res.status(400).json({ response: "Username and/or Email already exists." });+ return res+ .status(400)+ .json({ response: "Username and/or Email already exists." });}}