'use server' import { infer as zInfer } from 'zod' import { ResetSchema } from '@/schemas' import { getUserByEmail } from '@/data/user' import { sendPasswordResetEmail } from '@/actions/send-verification-email' export const reset = async (values: zInfer) => { const validatedFields = ResetSchema.safeParse(values) if (!validatedFields.success) { return { error: 'auth.form.error.invalid_fields' } } const { email } = validatedFields.data const existingUser = await getUserByEmail(email) if (!existingUser) { return { error: 'auth.email.success.reset_email_sent' } } return await sendPasswordResetEmail(existingUser.email as string, existingUser.name) }