"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { signIn, authClient } from "@/lib/auth-client"; export function LoginForm() { const router = useRouter(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setError(""); setLoading(true); const result = await signIn.email({ email, password }); if (result.error) { setError("Неверный email или пароль"); setLoading(false); return; } const session = await authClient.getSession(); const role = session.data?.user?.role; if (role === "admin") { router.push("/admin/dashboard"); } else if (role === "curator") { router.push("/curator/dashboard"); } else { router.push("/dashboard"); } router.refresh(); } return (
); }