mirror of
https://github.com/lukevella/rallly.git
synced 2025-08-06 09:59:00 +02:00
🔒️ Set max length on login email (#1440)
This commit is contained in:
parent
d57ca55e1a
commit
90caed9f5e
2 changed files with 12 additions and 6 deletions
|
@ -1,4 +1,5 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { usePostHog } from "@rallly/posthog/client";
|
import { usePostHog } from "@rallly/posthog/client";
|
||||||
import { Alert, AlertDescription, AlertTitle } from "@rallly/ui/alert";
|
import { Alert, AlertDescription, AlertTitle } from "@rallly/ui/alert";
|
||||||
import { Button } from "@rallly/ui/button";
|
import { Button } from "@rallly/ui/button";
|
||||||
|
@ -11,23 +12,28 @@ import { getProviders, signIn, useSession } from "next-auth/react";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
import { trpc } from "@/app/providers";
|
import { trpc } from "@/app/providers";
|
||||||
import { VerifyCode, verifyCode } from "@/components/auth/auth-forms";
|
import { VerifyCode, verifyCode } from "@/components/auth/auth-forms";
|
||||||
import { Spinner } from "@/components/spinner";
|
import { Spinner } from "@/components/spinner";
|
||||||
import { isSelfHosted } from "@/utils/constants";
|
import { isSelfHosted } from "@/utils/constants";
|
||||||
import { validEmail } from "@/utils/form-validation";
|
|
||||||
|
|
||||||
const allowGuestAccess = !isSelfHosted;
|
const allowGuestAccess = !isSelfHosted;
|
||||||
|
|
||||||
|
const loginFormSchema = z.object({
|
||||||
|
email: z.string().email().max(255),
|
||||||
|
});
|
||||||
|
|
||||||
|
type LoginFormData = z.infer<typeof loginFormSchema>;
|
||||||
|
|
||||||
export function LoginForm() {
|
export function LoginForm() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
const { register, handleSubmit, getValues, formState, setError } = useForm<{
|
const { register, handleSubmit, getValues, formState, setError } = useForm<LoginFormData>({
|
||||||
email: string;
|
|
||||||
}>({
|
|
||||||
defaultValues: { email: "" },
|
defaultValues: { email: "" },
|
||||||
|
resolver: zodResolver(loginFormSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data: providers } = useQuery(["providers"], getProviders, {
|
const { data: providers } = useQuery(["providers"], getProviders, {
|
||||||
|
@ -178,7 +184,7 @@ export function LoginForm() {
|
||||||
autoFocus={true}
|
autoFocus={true}
|
||||||
disabled={formState.isSubmitting}
|
disabled={formState.isSubmitting}
|
||||||
placeholder={t("emailPlaceholder")}
|
placeholder={t("emailPlaceholder")}
|
||||||
{...register("email", { validate: validEmail })}
|
{...register("email")}
|
||||||
/>
|
/>
|
||||||
{formState.errors.email?.message ? (
|
{formState.errors.email?.message ? (
|
||||||
<div className="mt-2 text-sm text-rose-500">
|
<div className="mt-2 text-sm text-rose-500">
|
||||||
|
|
|
@ -27,7 +27,7 @@ import { trpc } from "@/trpc/client";
|
||||||
import { useDayjs } from "@/utils/dayjs";
|
import { useDayjs } from "@/utils/dayjs";
|
||||||
|
|
||||||
const registerFormSchema = z.object({
|
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),
|
email: z.string().email().max(255),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue