"use client"; import dynamic from "next/dynamic"; import Link from "next/link"; import { useState } from "react"; import { useRouter, useSearchParams } from "next/navigation"; import { useAuth } from "@/context/AuthContext"; const labelCls = "flex flex-col gap-[0.35rem] text-[0.9rem] font-semibold text-[#444]"; const inputCls = "px-[0.85rem] py-[0.6rem] border border-[#ddd] rounded-lg text-base outline-none transition-all focus:border-[#e68672] focus:shadow-[0_0_0_3px_rgba(230,134,114,0.2)]"; const submitBtnCls = "mt-2 py-3 bg-[#e68672] text-white border-none rounded-lg text-base font-bold cursor-pointer transition-all hover:bg-[#d4705e] active:scale-[0.98] disabled:opacity-60 disabled:cursor-not-allowed"; function resolveNextPath(candidate) { if (!candidate || !candidate.startsWith("/")) return "/"; if (candidate.startsWith("//") || candidate.startsWith("/login") || candidate.startsWith("/register")) return "/"; return candidate; } function LoginPage() { const {login} = useAuth(); const router = useRouter(); const searchParams = useSearchParams(); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); async function handleSubmit(e) { e.preventDefault(); setError(""); setLoading(true); try { await login(username, password); router.push(resolveNextPath(searchParams.get("next"))); } catch (err) { setError(err.message); } finally { setLoading(false); } } return (

Log In

{error &&

{error}

}

Don't have an account?{" "} Register here

Forgot your password?{" "} Reset it here

); } export default dynamic(() => Promise.resolve(LoginPage), { ssr: false });