"use client"; import { useState } from "react"; import { useAuth } from "@/app/hooks/useAuth"; import { Input } from "../../component/ui/input"; import { Button } from "../../component/ui/button"; import Link from "next/link"; import { useRouter } from "next/navigation"; export default function LoginPage() { const { setToken } = useAuth(); const router = useRouter(); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(""); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); setError(""); const formData = new FormData(e.currentTarget); const email = formData.get("email"); const password = formData.get("password"); try { const response = await fetch("http://localhost:3000/api/auth/login", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ email, password }), }); if (!response.ok) { throw new Error("Invalid credentials"); } const data = await response.json(); console.log(data); setToken(data.access_token); router.push("/dashboard"); router.refresh(); } catch (err) { setError("Invalid email or password"); } finally { setIsLoading(false); } }; return (

Welcome back

Sign in to your account

{error && (
{error}
)}

Dont have an account?{" "} Sign up

); }