"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 (
Demo credentials:
admin / admin123
Loading...