Skip to content

Commit

Permalink
refactor: email handler (#18391)
Browse files Browse the repository at this point in the history
Co-authored-by: Bailey Pumfleet <[email protected]>
  • Loading branch information
Udit-takkar and pumfleet authored Dec 27, 2024
1 parent 7a80a5f commit cc1101a
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import type { NextApiRequest } from "next";

import { sendEmailVerification } from "@calcom/features/auth/lib/verifyEmail";
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
import getIP from "@calcom/lib/getIP";
import logger from "@calcom/lib/logger";
import { prisma } from "@calcom/prisma";
import { TRPCError } from "@calcom/trpc/server";

import type { TRPCContext } from "../../../createContext";
import type { TrpcSessionUser } from "../../../trpc";
import type { TResendVerifyEmailSchema } from "./resendVerifyEmail.schema";

type ResendEmailOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
req: TRPCContext["req"] | undefined;
};
input: TResendVerifyEmailSchema;
};
Expand All @@ -17,6 +23,13 @@ const log = logger.getSubLogger({ prefix: [`[[Auth] `] });

export const resendVerifyEmail = async ({ input, ctx }: ResendEmailOptions) => {
let emailToVerify = ctx.user.email;
const identifer = ctx.req ? getIP(ctx.req as NextApiRequest) : emailToVerify;

await checkRateLimitAndThrowError({
rateLimitingType: "core",
identifier: `resendVerifyEmail.${identifer}`,
});

let emailVerified = Boolean(ctx.user.emailVerified);
let secondaryEmail;
// If the input which is coming is not the current user's email, it could be a secondary email
Expand Down

0 comments on commit cc1101a

Please sign in to comment.