Files
formbricks/apps/web/modules/auth/verification-requested/actions.ts
T
2025-03-06 12:08:40 +00:00

26 lines
880 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";
import { ZUserEmail } from "@formbricks/types/user";
const ZResendVerificationEmailAction = z.object({
email: ZUserEmail,
});
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");
}
return await sendVerificationEmail(user);
});