added 2FA

This commit is contained in:
2024-04-26 22:16:21 +03:00
parent 53cadc289a
commit f17a002ac6
38 changed files with 1036 additions and 414 deletions

View File

@@ -7,6 +7,7 @@ import { getUserById } from '@/data/user'
import { AUTH_ERROR_URL, AUTH_LOGIN_URL } from '@/config/routes'
import { getCurrentLocale } from '@/locales/server'
import { type loc } from '@/config/locales'
import { getTwoFactorConfirmationByUserId } from '@/data/two-factor-confirmation'
declare module 'next-auth' {
interface Session {
@@ -44,7 +45,15 @@ export const {
// Prevent sign in without email verification
if (!existingUser?.emailVerified) return false
// TODO: Add 2FA check
if (existingUser.isTwoFactorEnabled) {
const twoFactorConfirmation = await getTwoFactorConfirmationByUserId(existingUser.id)
if (!twoFactorConfirmation) return false
// Delete 2FA for the next sign in
await db.twoFactorComfirmation.delete({
where: { id: twoFactorConfirmation.id },
})
}
return true
},