"use client" import { useState, useEffect, Suspense } from "react" import { signIn } from "next-auth/react" import { useRouter, useSearchParams } from "next/navigation" import Link from "next/link" function LoginForm() { const [email, setEmail] = useState("") const [password, setPassword] = useState("") const [error, setError] = useState("") const [loading, setLoading] = useState(false) const router = useRouter() const searchParams = useSearchParams() const isDemo = searchParams.get("demo") === "1" const doLogin = async (e?: React.FormEvent, demoEmail?: string, demoPass?: string) => { if (e) e.preventDefault() setError("") setLoading(true) const result = await signIn("credentials", { email: demoEmail || email, password: demoPass || password, redirect: false, }) if (result?.error) { setError("Invalid email or password") setLoading(false) } else { // Role-aware redirect: community leaders go to their scoped dashboard try { const session = await fetch("/api/auth/session").then(r => r.json()) const role = session?.user?.role if (role === "community_leader" || role === "volunteer") { router.push("/dashboard/community") } else { router.push("/dashboard") } } catch { router.push("/dashboard") } } } // eslint-disable-next-line react-hooks/exhaustive-deps useEffect(() => { if (isDemo) doLogin(undefined, "demo@pnpl.app", "demo1234") }, []) return (
{isDemo && (
P

Loading demo...

)} {!isDemo && ( <>
P

Welcome back

Sign in to your charity dashboard

{/* Google */}
or sign in with email
doLogin(e)} className="space-y-3"> {error && (
{error}
)} setEmail(e.target.value)} className="w-full border border-gray-200 px-4 py-3 text-sm focus:border-promise-blue focus:ring-1 focus:ring-promise-blue/20 outline-none transition-colors" placeholder="Email" required /> setPassword(e.target.value)} className="w-full border border-gray-200 px-4 py-3 text-sm focus:border-promise-blue focus:ring-1 focus:ring-promise-blue/20 outline-none transition-colors" placeholder="Password" required />
or

Don't have an account?{" "} Get Started Free

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