From 0d1bc763a97348815c527dcf95cb7bfaef75bd72 Mon Sep 17 00:00:00 2001 From: Dyuti Ballav Paul Date: Thu, 16 Jan 2025 01:21:00 +0530 Subject: [PATCH] Fixed bug adding zod validation of password before sending OTP --- apps/web/lib/actions/send-otp.ts | 5 +++-- apps/web/ui/auth/register/signup-email.tsx | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/web/lib/actions/send-otp.ts b/apps/web/lib/actions/send-otp.ts index 92dc490019..94e5755ea0 100644 --- a/apps/web/lib/actions/send-otp.ts +++ b/apps/web/lib/actions/send-otp.ts @@ -10,12 +10,13 @@ import { getIP } from "../api/utils"; import { generateOTP } from "../auth"; import { EMAIL_OTP_EXPIRY_IN } from "../auth/constants"; import z from "../zod"; -import { emailSchema } from "../zod/schemas/auth"; +import { emailSchema, passwordSchema } from "../zod/schemas/auth"; import { throwIfAuthenticated } from "./auth/throw-if-authenticated"; import { actionClient } from "./safe-action"; const schema = z.object({ email: emailSchema, + password: passwordSchema }); // Send OTP to email to verify account @@ -26,7 +27,7 @@ export const sendOtpAction = actionClient }) .use(throwIfAuthenticated) .action(async ({ parsedInput }) => { - const { email } = parsedInput; + const { email, password } = parsedInput; const { success } = await ratelimit(2, "1 m").limit(`send-otp:${getIP()}`); diff --git a/apps/web/ui/auth/register/signup-email.tsx b/apps/web/ui/auth/register/signup-email.tsx index cb1c4c4fa7..ae35ab0f6b 100644 --- a/apps/web/ui/auth/register/signup-email.tsx +++ b/apps/web/ui/auth/register/signup-email.tsx @@ -28,14 +28,14 @@ export const SignUpEmail = () => { setStep("verify"); }, onError: ({ error }) => { - toast.error(error.serverError); + toast.error(error.serverError||error.validationErrors?.email||error.validationErrors?.password||error.bindArgsValidationErrors); }, }); return ( <>
executeAsync({ email: data.email }))} + onSubmit={handleSubmit((data) => executeAsync({ email: data.email, password:data.password }))} >