Files
calendar/packages/trpc/server/routers/viewer/auth/verifyPassword.handler.ts
T
3c1297aa72 fix: calcom trpc sessio circle dep (#19893)
* fix trpc session circle dep

* fixes trpc session cirlce dep

* fix relative imports

* fix more imports to use types and not trpc

* fix exports

* Fixed types

---------

Co-authored-by: Keith Williams <keithwillcode@gmail.com>
2025-03-19 05:50:22 -03:00

35 lines
897 B
TypeScript

import { verifyPassword } from "@calcom/features/auth/lib/verifyPassword";
import { prisma } from "@calcom/prisma";
import { TRPCError } from "@trpc/server";
import type { TrpcSessionUser } from "../../../types";
import type { TVerifyPasswordInputSchema } from "./verifyPassword.schema";
type VerifyPasswordOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: TVerifyPasswordInputSchema;
};
export const verifyPasswordHandler = async ({ input, ctx }: VerifyPasswordOptions) => {
const userPassword = await prisma.userPassword.findUnique({
where: {
userId: ctx.user.id,
},
});
if (!userPassword?.hash) {
throw new TRPCError({ code: "INTERNAL_SERVER_ERROR" });
}
const passwordsMatch = await verifyPassword(input.passwordInput, userPassword.hash);
if (!passwordsMatch) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
return;
};