* add orgs upgrade badge to select * don't allow updating to if no teams or orgs plan * make sure only paying users can request verification codes * add new action helper function * remove kyc code * code clean up * fix verify button UI * fix type errors * add eventTypeRequiresConfirmation everywhere * address feedback --------- Co-authored-by: CarinaWolli <wollencarina@gmail.com>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { sendVerificationCode } from "@calcom/features/ee/workflows/lib/reminders/verifyPhoneNumber";
|
|
import hasKeyInMetadata from "@calcom/lib/hasKeyInMetadata";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
import { hasTeamPlanHandler } from "../teams/hasTeamPlan.handler";
|
|
import type { TSendVerificationCodeInputSchema } from "./sendVerificationCode.schema";
|
|
|
|
type SendVerificationCodeOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: TSendVerificationCodeInputSchema;
|
|
};
|
|
|
|
export const sendVerificationCodeHandler = async ({ ctx, input }: SendVerificationCodeOptions) => {
|
|
const { user } = ctx;
|
|
|
|
const isCurrentUsernamePremium =
|
|
user && hasKeyInMetadata(user, "isPremium") ? !!user.metadata.isPremium : false;
|
|
|
|
let isTeamsPlan = false;
|
|
if (!isCurrentUsernamePremium) {
|
|
const { hasTeamPlan } = await hasTeamPlanHandler({ ctx });
|
|
isTeamsPlan = !!hasTeamPlan;
|
|
}
|
|
|
|
if (!isCurrentUsernamePremium && !isTeamsPlan) {
|
|
throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
}
|
|
|
|
const { phoneNumber } = input;
|
|
return sendVerificationCode(phoneNumber);
|
|
};
|