added 2FA
This commit is contained in:
@@ -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
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user