mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-23 05:17:49 -05:00
afa192e5b9
Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
"use server";
|
|
|
|
import { z } from "zod";
|
|
import { ResourceNotFoundError } from "@formbricks/types/errors";
|
|
import { ZUserEmail } from "@formbricks/types/user";
|
|
import { actionClient } from "@/lib/utils/action-client";
|
|
import { ActionClientCtx } from "@/lib/utils/action-client/types/context";
|
|
import { getUserByEmail } from "@/modules/auth/lib/user";
|
|
import { applyIPRateLimit } from "@/modules/core/rate-limit/helpers";
|
|
import { rateLimitConfigs } from "@/modules/core/rate-limit/rate-limit-configs";
|
|
import { withAuditLogging } from "@/modules/ee/audit-logs/lib/handler";
|
|
import { sendVerificationEmail } from "@/modules/email";
|
|
|
|
const ZResendVerificationEmailAction = z.object({
|
|
email: ZUserEmail,
|
|
});
|
|
|
|
export const resendVerificationEmailAction = actionClient.inputSchema(ZResendVerificationEmailAction).action(
|
|
withAuditLogging(
|
|
"verificationEmailSent",
|
|
"user",
|
|
async ({ ctx, parsedInput }: { ctx: ActionClientCtx; parsedInput: Record<string, any> }) => {
|
|
await applyIPRateLimit(rateLimitConfigs.auth.verifyEmail);
|
|
|
|
const user = await getUserByEmail(parsedInput.email);
|
|
if (!user) {
|
|
throw new ResourceNotFoundError("user", parsedInput.email);
|
|
}
|
|
if (user.emailVerified) {
|
|
return {
|
|
success: true,
|
|
};
|
|
}
|
|
ctx.auditLoggingCtx.userId = user.id;
|
|
await sendVerificationEmail({ id: user.id, email: user.email, locale: user.locale });
|
|
return {
|
|
success: true,
|
|
};
|
|
}
|
|
)
|
|
);
|