From f2499167e4e2205057860c74055dd943cd180789 Mon Sep 17 00:00:00 2001 From: Cyber Date: Sun, 21 Jul 2024 20:00:14 +0200 Subject: [PATCH 1/2] fix: return an error on username change with no password --- src/api/routes/users/@me/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/api/routes/users/@me/index.ts b/src/api/routes/users/@me/index.ts index ad11a4281..95f572af8 100644 --- a/src/api/routes/users/@me/index.ts +++ b/src/api/routes/users/@me/index.ts @@ -120,7 +120,7 @@ router.patch( if (!body.password) throw FieldErrors({ password: { - message: req.t("auth:register.INVALID_PASSWORD"), + message: req.t("auth:login.INVALID_PASSWORD"), code: "INVALID_PASSWORD", }, }); @@ -162,6 +162,15 @@ router.patch( } } + if (!body.password) { + throw FieldErrors({ + password: { + message: req.t("auth:login.INVALID_PASSWORD"), + code: "INVALID_PASSWORD", + }, + }); + } + if (body.discriminator) { if ( await User.findOne({ From b641f1d2b4668c23db0add851cdd7179c6abe91e Mon Sep 17 00:00:00 2001 From: Cyber Date: Thu, 25 Jul 2024 19:41:56 +0200 Subject: [PATCH 2/2] fix: check for password only if `username` is present in body --- src/api/routes/users/@me/index.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/api/routes/users/@me/index.ts b/src/api/routes/users/@me/index.ts index 95f572af8..cddc3a087 100644 --- a/src/api/routes/users/@me/index.ts +++ b/src/api/routes/users/@me/index.ts @@ -160,15 +160,15 @@ router.patch( }, }); } - } - if (!body.password) { - throw FieldErrors({ - password: { - message: req.t("auth:login.INVALID_PASSWORD"), - code: "INVALID_PASSWORD", - }, - }); + if (!body.password) { + throw FieldErrors({ + password: { + message: req.t("auth:login.INVALID_PASSWORD"), + code: "INVALID_PASSWORD", + }, + }); + } } if (body.discriminator) {