"use client"; import { signIn } from "next-auth/react"; import { useRouter, useSearchParams } from "next/navigation"; import { useState, Suspense } from "react"; import Link from "next/link"; function LoginForm() { const router = useRouter(); const searchParams = useSearchParams(); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const registered = searchParams.get("registered") === "true"; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(""); setLoading(true); try { const result = await signIn("credentials", { username, password, redirect: false, }); if (result?.error) { setError("Invalid username or password"); } else { // Redirect to callbackUrl if present, otherwise to /map const callbackUrl = searchParams.get("callbackUrl") || "/map"; console.log('[Login] Redirecting to:', callbackUrl); router.push(callbackUrl); // Force a hard refresh to ensure middleware is applied router.refresh(); } } catch (err) { setError("An error occurred. Please try again."); } finally { setLoading(false); } }; return (

Location Tracker Admin

setUsername(e.target.value)} className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required />
setPassword(e.target.value)} className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required />
Forgot Password?
{registered && (
✓ Account created successfully! Please sign in.
)} {error && (
{error}
)}
Don't have an account? Sign up

Demo credentials:

admin / admin123

); } export default function LoginPage() { return (

Loading...

}> ); }