mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Improve requestEmailChangeOTP await logic
This commit is contained in:
@@ -196,8 +196,8 @@ export const userServiceFactory = ({
|
||||
};
|
||||
|
||||
const requestEmailChangeOTP = async ({ userId, newEmail }: TUpdateUserEmailDTO) => {
|
||||
const startTime = new Date();
|
||||
const changeEmailOTP = await userDAL.transaction(async (tx) => {
|
||||
const startTime = new Date();
|
||||
const user = await userDAL.findById(userId, tx);
|
||||
if (!user)
|
||||
throw new NotFoundError({ message: `User with ID '${userId}' not found`, name: "RequestEmailChangeOTP" });
|
||||
@@ -236,17 +236,16 @@ export const userServiceFactory = ({
|
||||
});
|
||||
}
|
||||
|
||||
// Force this function to have a minimum execution time of 2 seconds to avoid possible information disclosure about existing users
|
||||
const endTime = new Date();
|
||||
const timeDiff = endTime.getTime() - startTime.getTime();
|
||||
if (timeDiff < 2000) {
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(resolve, 2000 - timeDiff);
|
||||
});
|
||||
}
|
||||
|
||||
return { success: true, message: "Verification code sent to new email address" };
|
||||
});
|
||||
// Force this function to have a minimum execution time of 2 seconds to avoid possible information disclosure about existing users
|
||||
const endTime = new Date();
|
||||
const timeDiff = endTime.getTime() - startTime.getTime();
|
||||
if (timeDiff < 2000) {
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(resolve, 2000 - timeDiff);
|
||||
});
|
||||
}
|
||||
return changeEmailOTP;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user