🔒️ Set max length on login email (#1440)

This commit is contained in:
Luke Vella 2024-11-21 14:21:17 +00:00 committed by GitHub
parent d57ca55e1a
commit 90caed9f5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 6 deletions

View file

@ -1,4 +1,5 @@
"use client";
import { zodResolver } from "@hookform/resolvers/zod";
import { usePostHog } from "@rallly/posthog/client";
import { Alert, AlertDescription, AlertTitle } from "@rallly/ui/alert";
import { Button } from "@rallly/ui/button";
@ -11,23 +12,28 @@ import { getProviders, signIn, useSession } from "next-auth/react";
import React from "react";
import { useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { z } from "zod";
import { trpc } from "@/app/providers";
import { VerifyCode, verifyCode } from "@/components/auth/auth-forms";
import { Spinner } from "@/components/spinner";
import { isSelfHosted } from "@/utils/constants";
import { validEmail } from "@/utils/form-validation";
const allowGuestAccess = !isSelfHosted;
const loginFormSchema = z.object({
email: z.string().email().max(255),
});
type LoginFormData = z.infer<typeof loginFormSchema>;
export function LoginForm() {
const { t } = useTranslation();
const searchParams = useSearchParams();
const { register, handleSubmit, getValues, formState, setError } = useForm<{
email: string;
}>({
const { register, handleSubmit, getValues, formState, setError } = useForm<LoginFormData>({
defaultValues: { email: "" },
resolver: zodResolver(loginFormSchema),
});
const { data: providers } = useQuery(["providers"], getProviders, {
@ -178,7 +184,7 @@ export function LoginForm() {
autoFocus={true}
disabled={formState.isSubmitting}
placeholder={t("emailPlaceholder")}
{...register("email", { validate: validEmail })}
{...register("email")}
/>
{formState.errors.email?.message ? (
<div className="mt-2 text-sm text-rose-500">

View file

@ -27,7 +27,7 @@ import { trpc } from "@/trpc/client";
import { useDayjs } from "@/utils/dayjs";
const registerFormSchema = z.object({
name: z.string().min(1).max(100),
name: z.string().trim().min(1).max(100),
email: z.string().email().max(255),
});