{{#if framework == "nextjs"}} "use client"; {{/if}} import InputField from "@/components/global/form-field/input-field"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { FieldGroup } from "@/components/ui/field"; import { useLoginMutation } from "@/features/auth/queries/auth.mutations"; import type { ILoginPayload } from "@/features/auth/validators/login.validator"; import { loginZodSchema } from "@/features/auth/validators/login.validator"; import { zodResolver } from "@hookform/resolvers/zod"; {{#if framework == "nextjs"}} import Link from "next/link"; {{else}} import { Link, useSearchParams } from "react-router"; {{/if}} import { FormProvider, useForm } from "react-hook-form"; import SocialLoginButtons from "./social-login-buttons"; {{#if framework == "nextjs"}} export default function LoginForm({ searchParams, }: { searchParams?: { redirect?: string }; }) { const mutation = useLoginMutation(); const redirectPath = searchParams?.redirect || ""; {{else}} export default function LoginForm() { const mutation = useLoginMutation(); const [searchParams] = useSearchParams(); const redirectPath = searchParams.get("redirect") || ""; {{/if}} const form = useForm({ mode: "onTouched", resolver: zodResolver(loginZodSchema), defaultValues: { email: "", password: "", redirectPath }, }); async function onSubmit(values: ILoginPayload & { redirectPath?: string }) { try { await mutation.mutateAsync({ email: values.email, password: values.password, redirectPath: values.redirectPath, }); } catch {} } return ( Sign in to your account Enter your email and password to sign in
{{#if framework == "nextjs"}} Don't have an account? Create one {{else}} Don't have an account? Create one {{/if}}
{{#if framework == "nextjs"}} Forgot password? {{else}} Forgot password? {{/if}}
); }