mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
feat: restrict app access for unverified users
This commit is contained in:
@ -10,6 +10,7 @@ import GoogleProvider from 'next-auth/providers/google';
|
||||
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { ONE_DAY } from '../constants/time';
|
||||
import { isTwoFactorAuthenticationEnabled } from '../server-only/2fa/is-2fa-availble';
|
||||
import { validateTwoFactorAuthentication } from '../server-only/2fa/validate-2fa';
|
||||
import { getUserByEmail } from '../server-only/user/get-user-by-email';
|
||||
@ -69,6 +70,17 @@ export const NEXT_AUTH_OPTIONS: AuthOptions = {
|
||||
}
|
||||
}
|
||||
|
||||
const userCreationDate = user?.createdAt;
|
||||
const createdWithinLast72Hours = userCreationDate > new Date(Date.now() - ONE_DAY * 3);
|
||||
|
||||
/*
|
||||
avoid messing with the users who signed up before the email verification requirement
|
||||
the error is thrown only if the user doesn't have a verified email and the account was created within the last 72 hours
|
||||
*/
|
||||
if (!user.emailVerified && createdWithinLast72Hours) {
|
||||
throw new Error(ErrorCode.UNVERIFIED_EMAIL);
|
||||
}
|
||||
|
||||
return {
|
||||
id: Number(user.id),
|
||||
email: user.email,
|
||||
|
||||
@ -19,4 +19,5 @@ export const ErrorCode = {
|
||||
INCORRECT_PASSWORD: 'INCORRECT_PASSWORD',
|
||||
MISSING_ENCRYPTION_KEY: 'MISSING_ENCRYPTION_KEY',
|
||||
MISSING_BACKUP_CODE: 'MISSING_BACKUP_CODE',
|
||||
UNVERIFIED_EMAIL: 'UNVERIFIED_EMAIL',
|
||||
} as const;
|
||||
|
||||
Reference in New Issue
Block a user