mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-22 13:39:39 -05:00
f80d1b32b7
Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com> Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
26 lines
895 B
TypeScript
26 lines
895 B
TypeScript
"use server";
|
|
|
|
import { actionClient } from "@/lib/utils/action-client";
|
|
import { getUserByEmail } from "@/modules/auth/lib/user";
|
|
import { sendVerificationEmail } from "@/modules/email";
|
|
import { z } from "zod";
|
|
import { InvalidInputError, ResourceNotFoundError } from "@formbricks/types/errors";
|
|
|
|
const ZResendVerificationEmailAction = z.object({
|
|
email: z.string().max(255).email({ message: "Invalid email" }),
|
|
});
|
|
|
|
export const resendVerificationEmailAction = actionClient
|
|
.schema(ZResendVerificationEmailAction)
|
|
.action(async ({ parsedInput }) => {
|
|
const user = await getUserByEmail(parsedInput.email);
|
|
if (!user) {
|
|
throw new ResourceNotFoundError("user", parsedInput.email);
|
|
}
|
|
if (user.emailVerified) {
|
|
throw new InvalidInputError("Email address has already been verified");
|
|
}
|
|
await sendVerificationEmail(user);
|
|
return { success: true };
|
|
});
|