2023-07-31 17:51:11 +00:00
|
|
|
import { ZVerifyCodeInputSchema } from "@calcom/prisma/zod-utils";
|
|
|
|
|
2023-05-09 19:27:05 +00:00
|
|
|
import authedProcedure from "../../../procedures/authedProcedure";
|
2023-07-31 17:51:11 +00:00
|
|
|
import publicProcedure from "../../../procedures/publicProcedure";
|
2023-05-09 19:27:05 +00:00
|
|
|
import { router } from "../../../trpc";
|
2023-04-25 22:39:47 +00:00
|
|
|
import { ZChangePasswordInputSchema } from "./changePassword.schema";
|
2023-07-31 17:51:11 +00:00
|
|
|
import { ZSendVerifyEmailCodeSchema } from "./sendVerifyEmailCode.schema";
|
2023-04-25 22:39:47 +00:00
|
|
|
import { ZVerifyPasswordInputSchema } from "./verifyPassword.schema";
|
|
|
|
|
|
|
|
type AuthRouterHandlerCache = {
|
|
|
|
changePassword?: typeof import("./changePassword.handler").changePasswordHandler;
|
|
|
|
verifyPassword?: typeof import("./verifyPassword.handler").verifyPasswordHandler;
|
2023-07-31 17:51:11 +00:00
|
|
|
verifyCodeUnAuthenticated?: typeof import("./verifyCodeUnAuthenticated.handler").verifyCodeUnAuthenticatedHandler;
|
2023-06-07 07:27:48 +00:00
|
|
|
resendVerifyEmail?: typeof import("./resendVerifyEmail.handler").resendVerifyEmail;
|
2023-07-31 17:51:11 +00:00
|
|
|
sendVerifyEmailCode?: typeof import("./sendVerifyEmailCode.handler").sendVerifyEmailCodeHandler;
|
2023-04-25 22:39:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const UNSTABLE_HANDLER_CACHE: AuthRouterHandlerCache = {};
|
|
|
|
|
|
|
|
export const authRouter = router({
|
|
|
|
changePassword: authedProcedure.input(ZChangePasswordInputSchema).mutation(async ({ input, ctx }) => {
|
|
|
|
if (!UNSTABLE_HANDLER_CACHE.changePassword) {
|
|
|
|
UNSTABLE_HANDLER_CACHE.changePassword = await import("./changePassword.handler").then(
|
|
|
|
(mod) => mod.changePasswordHandler
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unreachable code but required for type safety
|
|
|
|
if (!UNSTABLE_HANDLER_CACHE.changePassword) {
|
|
|
|
throw new Error("Failed to load handler");
|
|
|
|
}
|
|
|
|
|
|
|
|
return UNSTABLE_HANDLER_CACHE.changePassword({
|
|
|
|
ctx,
|
|
|
|
input,
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
verifyPassword: authedProcedure.input(ZVerifyPasswordInputSchema).mutation(async ({ input, ctx }) => {
|
|
|
|
if (!UNSTABLE_HANDLER_CACHE.verifyPassword) {
|
|
|
|
UNSTABLE_HANDLER_CACHE.verifyPassword = await import("./verifyPassword.handler").then(
|
|
|
|
(mod) => mod.verifyPasswordHandler
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unreachable code but required for type safety
|
|
|
|
if (!UNSTABLE_HANDLER_CACHE.verifyPassword) {
|
|
|
|
throw new Error("Failed to load handler");
|
|
|
|
}
|
|
|
|
|
|
|
|
return UNSTABLE_HANDLER_CACHE.verifyPassword({
|
|
|
|
ctx,
|
|
|
|
input,
|
|
|
|
});
|
|
|
|
}),
|
2023-07-31 17:51:11 +00:00
|
|
|
|
|
|
|
verifyCodeUnAuthenticated: publicProcedure.input(ZVerifyCodeInputSchema).mutation(async ({ input }) => {
|
|
|
|
if (!UNSTABLE_HANDLER_CACHE.verifyCodeUnAuthenticated) {
|
|
|
|
UNSTABLE_HANDLER_CACHE.verifyCodeUnAuthenticated = await import(
|
|
|
|
"./verifyCodeUnAuthenticated.handler"
|
|
|
|
).then((mod) => mod.verifyCodeUnAuthenticatedHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unreachable code but required for type safety
|
|
|
|
if (!UNSTABLE_HANDLER_CACHE.verifyCodeUnAuthenticated) {
|
|
|
|
throw new Error("Failed to load handler");
|
|
|
|
}
|
|
|
|
|
|
|
|
return UNSTABLE_HANDLER_CACHE.verifyCodeUnAuthenticated({
|
|
|
|
input,
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
sendVerifyEmailCode: publicProcedure.input(ZSendVerifyEmailCodeSchema).mutation(async ({ input }) => {
|
|
|
|
if (!UNSTABLE_HANDLER_CACHE.sendVerifyEmailCode) {
|
|
|
|
UNSTABLE_HANDLER_CACHE.sendVerifyEmailCode = await import("./sendVerifyEmailCode.handler").then(
|
|
|
|
(mod) => mod.sendVerifyEmailCodeHandler
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unreachable code but required for type safety
|
|
|
|
if (!UNSTABLE_HANDLER_CACHE.sendVerifyEmailCode) {
|
|
|
|
throw new Error("Failed to load handler");
|
|
|
|
}
|
|
|
|
|
|
|
|
return UNSTABLE_HANDLER_CACHE.sendVerifyEmailCode({
|
|
|
|
input,
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
2023-06-07 07:27:48 +00:00
|
|
|
resendVerifyEmail: authedProcedure.mutation(async ({ ctx }) => {
|
|
|
|
if (!UNSTABLE_HANDLER_CACHE.resendVerifyEmail) {
|
|
|
|
UNSTABLE_HANDLER_CACHE.resendVerifyEmail = await import("./resendVerifyEmail.handler").then(
|
|
|
|
(mod) => mod.resendVerifyEmail
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!UNSTABLE_HANDLER_CACHE.resendVerifyEmail) {
|
|
|
|
throw new Error("Failed to load handler");
|
|
|
|
}
|
|
|
|
|
|
|
|
return UNSTABLE_HANDLER_CACHE.resendVerifyEmail({
|
|
|
|
ctx,
|
|
|
|
});
|
|
|
|
}),
|
2023-04-25 22:39:47 +00:00
|
|
|
});
|