From c3f7953bdb6145e418057f22515ac28a61afa0f9 Mon Sep 17 00:00:00 2001 From: elweyn Date: Mon, 14 Mar 2022 12:32:42 +0100 Subject: [PATCH] Create a query to check if OptIn code is not to old. --- backend/src/graphql/resolver/UserResolver.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 4d1454e86..3a70c46ee 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -486,8 +486,8 @@ export class UserResolver { // Code is only valid for 10minutes const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime() - if (timeElapsed > 10 * 60 * 1000) { - throw new Error('Code is older than 10 minutes') + if (timeElapsed > parseInt(CONFIG.RESEND_TIME.toString()) * 60 * 1000) { + throw new Error('Code is older than ' + parseInt(CONFIG.RESEND_TIME.toString()) + ' minutes') } // load user @@ -558,6 +558,19 @@ export class UserResolver { return true } + @Authorized([RIGHTS.QUERY_OPT_IN]) + @Query(() => Boolean) + async queryOptIn(@Arg('optIn') optIn: string): Promise { + const optInCode = await LoginEmailOptIn.findOneOrFail({ verificationCode: optIn }) + console.log('optInCode', optInCode) + // Code is only valid for 10minutes + const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime() + if (timeElapsed > parseInt(CONFIG.RESEND_TIME.toString()) * 60 * 1000) { + throw new Error('Code is older than ' + parseInt(CONFIG.RESEND_TIME.toString()) + ' minutes') + } + return true + } + @Authorized([RIGHTS.UPDATE_USER_INFOS]) @Mutation(() => Boolean) async updateUserInfos(