"use client" import Link from "next/link" import { useState } from "react" import { useRouter } from "next/navigation" import { Mail } from "lucide-react" import Cookies from "js-cookie" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Alert, AlertDescription } from "@/components/ui/alert" export default function Login() { const [email, setEmail] = useState("") const [errorMessage, setErrorMessage] = useState("") const [isLoading, setIsLoading] = useState(false) const router = useRouter() const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setIsLoading(true) setErrorMessage("") try { const response = await fetch('http://localhost:3001/auth/login', { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ email }), }) const data = await response.json() if (response.ok && data.success) { Cookies.set("stageTwoKey", data.stageTwoKey) Cookies.set("email", email) router.push("/account/login/code") } else { setErrorMessage(data.error || "An unknown error occurred.") } } catch (error) { console.error("There was a problem with requesting a magic code:", error) setErrorMessage("An unexpected error occurred. Please try again.") } finally { setIsLoading(false) } } return (