yo-next-auth/data/user.ts
2024-04-26 22:16:21 +03:00

37 lines
917 B
TypeScript

'use server'
import { User } from '@prisma/client'
import db from '@/lib/db'
import journal from '@/actions/logger'
export const getUserByEmail = async (email: string): Promise<User | null> => {
try {
return await db.user.findUnique({ where: { email } })
} catch (err) {
journal.error({ getUserByEmail: err, email })
return null
}
}
export const getUserById = async (id: string): Promise<User | null> => {
try {
return await db.user.findUnique({ where: { id } })
} catch (err) {
journal.error({ getUserById: err, id })
return null
}
}
export const updateUserEmailVerified = async (id: string, email: string) => {
try {
await db.user.update({
where: { id },
data: {
email, emailVerified: new Date(),
},
})
} catch (err) {
journal.error({ updateUserEmailVerified: err, id, email })
return { error: 'db.error.update.user_data' }
}
}