"use client" import { useState } from "react" import { useRouter } from "next/navigation" import { Button } from "@/shared/ui/button" import { Logo } from "@/widgets/landing" import Link from "next/link" import { useAuth } from "@/src/app/providers/auth-provider" export default function LoginPage() { const [email, setEmail] = useState("") const [password, setPassword] = useState("") const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState("") const router = useRouter() const { login } = useAuth() const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setIsLoading(true) setError("") try { const response = await fetch("/api/auth/login", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ email, password }), }) const data = await response.json() if (response.ok) { // Update auth context with user data login(data.token, data.user) // Redirect to documents page router.push("/documents") } else { setError(data.error || "Login failed") } } catch (error) { setError("An error occurred. Please try again.") } finally { setIsLoading(false) } } return (

Sign in to your account

Or{" "} create a new account

{error && (
{error}
)}
setEmail(e.target.value)} className="mt-1 block w-full px-3 py-2 border border-input rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent" placeholder="Enter your email" />
setPassword(e.target.value)} className="mt-1 block w-full px-3 py-2 border border-input rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent" placeholder="Enter your password" />
) }