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

@@ -1,8 +1,7 @@
'use server'
import db from '@/lib/db'
import { getVerificationTokenByToken } from '@/data/verification-token'
import { getUserByEmail } from '@/data/user'
import { deleteVerificationToken, getVerificationTokenByToken } from '@/data/verification-token'
import { getUserByEmail, updateUserEmailVerified } from '@/data/user'
export const userVerification = async (token: string) => {
const existingToken = await getVerificationTokenByToken(token)
@@ -17,25 +16,9 @@ export const userVerification = async (token: string) => {
if (!existingUser) return { error: 'Email associated with token not found!' }
try {
await db.user.update({
where: { id: existingUser.id }, data: {
email: existingToken.email, emailVerified: new Date(),
},
})
} catch (e) {
console.error(e)
return { error: 'db.error.update.user_data' }
}
await updateUserEmailVerified(existingUser.id, existingToken.email)
try {
await db.verificationToken.delete({
where: { id: existingToken.id },
})
} catch (e) {
// TODO: log error on disc or db
console.error(e)
}
await deleteVerificationToken(existingToken.id)
return { success: 'User verified!' }
}