From e20182bff39582a4f56e56e59ca0789a69d1beb0 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 16 Mar 2022 05:21:58 +0100 Subject: [PATCH] Change the parseInt of CONFIG.EMAIL_CODE_VALID_TIME.toString with only the int of the config. --- backend/src/graphql/resolver/UserResolver.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index d36dc3918..99586fda4 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -158,7 +158,7 @@ const createEmailOptIn = async ( }) if (emailOptIn) { const timeElapsed = Date.now() - new Date(emailOptIn.updatedAt).getTime() - if (timeElapsed <= parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) { + if (timeElapsed <= CONFIG.EMAIL_CODE_VALID_TIME * 60 * 1000) { throw new Error(`email already sent less than $(CONFIG.EMAIL_CODE_VALID_TIME} minutes ago`) } else { emailOptIn.updatedAt = new Date() @@ -187,7 +187,7 @@ const getOptInCode = async (loginUserId: number): Promise => { // Check for 10 minute delay if (optInCode) { const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime() - if (timeElapsed <= parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) { + if (timeElapsed <= CONFIG.EMAIL_CODE_VALID_TIME * 60 * 1000) { throw new Error(`email already sent less than $(CONFIG.EMAIL_CODE_VALID_TIME} minutes ago`) } else { optInCode.updatedAt = new Date() @@ -482,7 +482,7 @@ export class UserResolver { // Code is only valid for 10minutes const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime() - if (timeElapsed > parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) { + if (timeElapsed > CONFIG.EMAIL_CODE_VALID_TIME * 60 * 1000) { throw new Error(`email already sent less than $(CONFIG.EMAIL_CODE_VALID_TIME} minutes ago`) } @@ -560,7 +560,7 @@ export class UserResolver { const optInCode = await LoginEmailOptIn.findOneOrFail({ verificationCode: optIn }) // Code is only valid for 10minutes const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime() - if (timeElapsed > parseInt(CONFIG.EMAIL_CODE_VALID_TIME.toString()) * 60 * 1000) { + if (timeElapsed > CONFIG.EMAIL_CODE_VALID_TIME * 60 * 1000) { throw new Error(`email already sent less than $(CONFIG.EMAIL_CODE_VALID_TIME} minutes ago`) } return true