* booker email verification changes * name type fix * use totp and code * prisma schema styling * refactor: code Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> * fix: book event form Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> * fix: type error Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> * fix: type errors Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> * fix: unit tests Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> * refactor: move verifycodedialog from ui and to features/bookings * fix: type error --------- Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> Co-authored-by: rkreddy99 <rreddy@e2clouds.com> Co-authored-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
28 lines
759 B
TypeScript
28 lines
759 B
TypeScript
import { createHash } from "crypto";
|
|
import { totp } from "otplib";
|
|
|
|
import type { ZVerifyCodeInputSchema } from "@calcom/prisma/zod-utils";
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
type VerifyTokenOptions = {
|
|
input: ZVerifyCodeInputSchema;
|
|
};
|
|
|
|
export const verifyCodeUnAuthenticatedHandler = async ({ input }: VerifyTokenOptions) => {
|
|
const { email, code } = input;
|
|
|
|
if (!email || !code) throw new TRPCError({ code: "BAD_REQUEST" });
|
|
|
|
const secret = createHash("md5")
|
|
.update(email + process.env.CALENDSO_ENCRYPTION_KEY)
|
|
.digest("hex");
|
|
|
|
totp.options = { step: 900 };
|
|
const isValidToken = totp.check(code, secret);
|
|
|
|
if (!isValidToken) throw new TRPCError({ code: "BAD_REQUEST", message: "invalid_code" });
|
|
|
|
return isValidToken;
|
|
};
|