From e8b24b368435eec1c2ab9c0e4cebb5d0170fdb08 Mon Sep 17 00:00:00 2001 From: RealMANI <96433859+ImAaronFR@users.noreply.github.com> Date: Wed, 16 Feb 2022 11:15:37 +0330 Subject: [PATCH] [Fix] Invisible space username (#639) You can send only spaces to the server and have a invisible username, this way you can remove the spaces and check and if it wasn't null after you know it's not just spaces --- api/src/routes/users/@me/index.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api/src/routes/users/@me/index.ts b/api/src/routes/users/@me/index.ts index 1959704a..acca8910 100644 --- a/api/src/routes/users/@me/index.ts +++ b/api/src/routes/users/@me/index.ts @@ -57,6 +57,13 @@ router.patch("/", route({ body: "UserModifySchema" }), async (req: Request, res: user.data.hash = await bcrypt.hash(body.new_password, 12); } + var check_username = body?.username?.replace(/\s/g, ''); + if(!check_username) { + throw FieldErrors({ + username: { code: "BASE_TYPE_REQUIRED", message: req.t("common:field.BASE_TYPE_REQUIRED") } + }); + } + await user.save(); // @ts-ignore