import dataService from '@/lib/data-service'; "use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Image from "next/image"; import Link from "next/link"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; export default function LoginPage() { const [username, setUsername] = useState(""); // ✅ Fixed incorrect state name const [password, setPassword] = useState(""); const [rememberMe, setRememberMe] = useState(false); // ✅ Fixed missing state const [error, setError] = useState(""); const router = useRouter(); async function handleLogin(e: React.FormEvent) { e.preventDefault(); setError(""); const res = await dataService.fetchData("https://internal-api.inboxi.ng/api/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username, password }), }); if (res.ok) { const data = await res.json(); console.log(data); document.cookie = `Authorization=${data.token}; path=/; Secure; SameSite=Strict; max-age=604800`; router.push("/dashboard"); } else { const data = await res.json(); setError(data.error || "Invalid credentials"); } } return (
Please sign in to your account
{error}
} {/* ✅ Display login errors */}Don't have an account?{" "} Sign up