Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Refactor OTP sending logic and update signup form validation

Kiran Kcc138fc6827d
diff --git a/apps/web/lib/actions/send-otp.ts b/apps/web/lib/actions/send-otp.ts
index 94e5755ea0..657c3cba8d 100644
--- a/apps/web/lib/actions/send-otp.ts
+++ b/apps/web/lib/actions/send-otp.ts
@@ -16,7 +16,7 @@ import { actionClient } from "./safe-action";
const schema = z.object({
email: emailSchema,
- password: passwordSchema
+ password: passwordSchema,
});
// Send OTP to email to verify account
@@ -27,7 +27,7 @@ export const sendOtpAction = actionClient
})
.use(throwIfAuthenticated)
.action(async ({ parsedInput }) => {
- const { email, password } = parsedInput;
+ const { email } = 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 ae35ab0f6b..9ca0156597 100644
--- a/apps/web/ui/auth/register/signup-email.tsx
+++ b/apps/web/ui/auth/register/signup-email.tsx
@@ -28,39 +28,40 @@ export const SignUpEmail = () => {
setStep("verify");
},
onError: ({ error }) => {
- toast.error(error.serverError||error.validationErrors?.email||error.validationErrors?.password||error.bindArgsValidationErrors);
+ toast.error(
+ error.serverError ||
+ error.validationErrors?.email?.[0] ||
+ error.validationErrors?.password?.[0],
+ );
},
});
return (
- <>
- <form
- onSubmit={handleSubmit((data) => executeAsync({ email: data.email, password:data.password }))}
- >
- <div className="flex flex-col space-y-4">
- <Input
- type="email"
- placeholder="Work Email"
- autoComplete="email"
- required
- {...register("email")}
- error={errors.email?.message}
- />
- <Input
- type="password"
- placeholder="Password"
- required
- {...register("password")}
- error={errors.password?.message}
- />
- <Button
- type="submit"
- text={isExecuting ? "Submitting..." : "Sign Up"}
- disabled={isExecuting}
- loading={isExecuting}
- />
- </div>
- </form>
- </>
+ <form onSubmit={handleSubmit(async (data) => await executeAsync(data))}>
+ <div className="flex flex-col space-y-4">
+ <Input
+ type="email"
+ placeholder="Work Email"
+ autoComplete="email"
+ required
+ {...register("email")}
+ error={errors.email?.message}
+ />
+ <Input
+ type="password"
+ placeholder="Password"
+ required
+ {...register("password")}
+ error={errors.password?.message}
+ minLength={8}
+ />
+ <Button
+ type="submit"
+ text={isExecuting ? "Submitting..." : "Sign Up"}
+ disabled={isExecuting}
+ loading={isExecuting}
+ />
+ </div>
+ </form>
);
};