mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-27 16:59:19 -06:00
Co-authored-by: Harsh Bhat <90265455+harshsbhat@users.noreply.github.com> Co-authored-by: Johannes <johannes@formbricks.com> Co-authored-by: Piyush Gupta <56182734+gupta-piyush19@users.noreply.github.com> Co-authored-by: Aditya <162564995+Naidu-4444@users.noreply.github.com> Co-authored-by: Piyush Gupta <piyushguptaa2z123@gmail.com> Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com> Co-authored-by: Dhruwang Jariwala <67850763+Dhruwang@users.noreply.github.com> Co-authored-by: Johannes <72809645+jobenjada@users.noreply.github.com> Co-authored-by: Jakob Schott <154420406+jakobsitory@users.noreply.github.com> Co-authored-by: Suraj <surajsuthar0067@gmail.com> Co-authored-by: Kshitij Sharma <63995641+kshitij-codes@users.noreply.github.com> Co-authored-by: Dhruwang <dhruwangjariwala18@gmail.com> Co-authored-by: Matti Nannt <mail@matthiasnannt.com>
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
"use server";
|
|
|
|
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";
|
|
import { z } from "zod";
|
|
import { ResourceNotFoundError } from "@formbricks/types/errors";
|
|
import { ZUserEmail } from "@formbricks/types/user";
|
|
|
|
const ZResendVerificationEmailAction = z.object({
|
|
email: ZUserEmail,
|
|
});
|
|
|
|
export const resendVerificationEmailAction = actionClient.schema(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(user);
|
|
return {
|
|
success: true,
|
|
};
|
|
}
|
|
)
|
|
);
|