finished reset password & other changes
This commit is contained in:
24
actions/reset.ts
Normal file
24
actions/reset.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
'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<typeof ResetSchema>) => {
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user