Create a query to check if OptIn code is not to old.

This commit is contained in:
elweyn 2022-03-14 12:32:42 +01:00
parent 08dd7c3518
commit c3f7953bdb

View File

@ -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<boolean> {
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(