fix(usersettings): exclude current user when checking for existing email (#1689)

This update modifies the user settings endpoint so that, when validating email uniqueness, the query
excludes the current user’s own record (using id: Not(user.id))
This commit is contained in:
fallenbagel
2025-05-31 17:10:13 +08:00
committed by GitHub
parent 110adfaf66
commit ea7e68fc99

View File

@@ -18,6 +18,7 @@ import { ApiError } from '@server/types/error';
import { getHostname } from '@server/utils/getHostname';
import { Router } from 'express';
import net from 'net';
import { Not } from 'typeorm';
import { canMakePermissionsChange } from '.';
const isOwnProfile = (): Middleware => {
@@ -125,8 +126,9 @@ userSettingsRoutes.post<
}
const existingUser = await userRepository.findOne({
where: { email: user.email },
where: { email: user.email, id: Not(user.id) },
});
if (oldEmail !== user.email && existingUser) {
throw new ApiError(400, ApiErrorCode.InvalidEmail);
}