From 4a33ca0368de864a96f681c185f852e01427b92c Mon Sep 17 00:00:00 2001 From: JCBSComputer Date: Wed, 1 Jul 2026 16:36:48 +0200 Subject: [PATCH] Fixed AI Auto Launch, Fixed Client Login not working --- package.json | 2 +- src/app/client-portal/login/page.tsx | 24 +++++++++++++++++++++++- src/app/login/page.tsx | 21 +++++++++++++++++---- src/components/ai/ai-chat.tsx | 4 ++-- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 6d69b37..5c589b1 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "repair:ci": "node scripts/code-repair-agent.mjs --ci", "build:fix": "npm run build 2>&1 || node scripts/code-repair-agent.mjs --ci", "build": "next build", - "start": "next start -p 3006", + "start": "node scripts/ensure-ollama.mjs && concurrently -n AI,NEXT -c cyan,green \"npm run dev:rust\" \"next start -p 3006\"", "lint": "eslint" }, "dependencies": { diff --git a/src/app/client-portal/login/page.tsx b/src/app/client-portal/login/page.tsx index 7a70fdb..3191261 100644 --- a/src/app/client-portal/login/page.tsx +++ b/src/app/client-portal/login/page.tsx @@ -14,16 +14,26 @@ export default function ClientLoginPage() { const [checking, setChecking] = useState(true) const [debugInfo, setDebugInfo] = useState("") + const [sessionUser, setSessionUser] = useState<{ email: string; role: string } | null>(null) + useEffect(() => { fetch("/api/auth/me", { credentials: "include" }) .then((r) => r.json()) .then((data) => { if (data.user?.role === "client") router.push("/client-portal/dashboard") - else setChecking(false) + else { + if (data.user) setSessionUser({ email: data.user.email, role: data.user.role }) + setChecking(false) + } }) .catch(() => setChecking(false)) }, [router]) + const handleSignOut = async () => { + await fetch("/api/auth/logout", { method: "POST" }) + setSessionUser(null) + } + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setLoading(true) @@ -83,6 +93,18 @@ export default function ClientLoginPage() {

Sign in to view your projects and invoices

+ {sessionUser && ( +
+
+ Signed in as {sessionUser.email} + {(sessionUser.role || "").replace("_", " ")} +
+ +
+ )} +
diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index cb5f887..6c28596 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -42,9 +42,17 @@ function LoginForm() { useEffect(() => { fetch("/api/auth/me", { credentials: "include" }) - .then((r) => { - if (r.ok) router.push("/dashboard") - else setCheckingSession(false) + .then(async (r) => { + if (r.ok) { + const data = await r.json().catch(() => ({})) + if (data.user?.role === "client") { + window.location.href = "/client-portal/dashboard" + } else { + router.push("/dashboard") + } + } else { + setCheckingSession(false) + } }) .catch(() => setCheckingSession(false)) }, [router]) @@ -239,11 +247,16 @@ function LoginForm() { }) if (res.ok) { + const loginData = await res.json().catch(() => ({})) localStorage.removeItem(WEBSITE_THEME_KEY) const root = document.documentElement root.className = root.className.split(" ").filter((c) => !c.startsWith("theme-")).join(" ").trim() const redirectTo = searchParams.get("redirect") || "/dashboard" - router.push(redirectTo) + if (loginData.user?.role === "client") { + window.location.href = "/client-portal/dashboard" + } else { + router.push(redirectTo) + } } else { const data = await res.json().catch(() => ({})) setError(data.error || "Invalid email or password.") diff --git a/src/components/ai/ai-chat.tsx b/src/components/ai/ai-chat.tsx index 95d9e68..97ef6cb 100644 --- a/src/components/ai/ai-chat.tsx +++ b/src/components/ai/ai-chat.tsx @@ -187,8 +187,8 @@ export const AIChat = forwardRef<{ fillInput: (text: string) => void }, AIChatPr }, []) useEffect(() => { - checkServer() - }, [checkServer]) + setBootState("ready") + }, []) useEffect(() => { messagesEndRef.current?.scrollIntoView({ behavior: "smooth" })