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