"use client"; import { useForm } from "react-hook-form"; import { signin } from "./actions"; // optional: remove if you use your own API import { Card, CardContent, CardFooter, CardHeader, CardTitle, CardDescription, } from "@/components/ui/card"; import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { toast, Bounce } from "react-toastify"; import { useRouter } from "next/navigation"; type FormData = { name: string; password: string; }; export default function SignInPage() { const { register, handleSubmit, formState } = useForm({ mode: "onSubmit", }); const router = useRouter(); async function onSubmit(data: FormData) { // Example with next-auth credential sign in (optional) // If you use your own API, replace this block with a fetch to /api/auth/signin const res = await signin(data.name, data.password); if (res) { router.push("/dashboard"); } else { toast.error("Falsche Anmeldedaten!", { position: "bottom-right", autoClose: 5000, hideProgressBar: false, closeOnClick: false, pauseOnHover: true, draggable: true, progress: undefined, theme: "light", transition: Bounce, }); } } return (
Anmelden Nutze deinen Namen und Passwort zum anmelden.
{formState.errors.name && (

{formState.errors.name.message}

)}
{formState.errors.password && (

{formState.errors.password.type === "minLength" ? "Password must be at least 6 characters" : formState.errors.password.message}

)}
); }