summary refs log tree commit diff
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-25 11:14:05 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-25 11:14:05 +1000
commit38e0acdefa04fe7bd5008146a715ee8b43bd73c9 (patch)
tree03ce57d2ce0145e19607392fe88739f4baca3262
parentTypeorm doesn't even use the cache for BaseEntity.* methods (diff)
downloadserver-38e0acdefa04fe7bd5008146a715ee8b43bd73c9.tar.xz
Add discrim verify in PATCH /users/@me
-rw-r--r--api/src/routes/users/@me/index.ts8
1 files changed, 8 insertions, 0 deletions
diff --git a/api/src/routes/users/@me/index.ts b/api/src/routes/users/@me/index.ts
index dc0d1cb1..36b62b55 100644
--- a/api/src/routes/users/@me/index.ts
+++ b/api/src/routes/users/@me/index.ts
@@ -77,6 +77,14 @@ router.patch("/", route({ body: "UserModifySchema" }), async (req: Request, res:
 		}
 	}
 
+	if (body.discriminator) {
+		if (await User.findOne({ where: { discriminator: body.discriminator, username: body.username || user.username } })) {
+			throw FieldErrors({
+				discriminator: { code: "INVALID_DISCRIMINATOR", message: "This discriminator is already in use." }
+			});
+		}
+	}
+
 	user.assign(body);
 	await user.save();