From 307027faae04b16e029ae6b8eb97540d7647e461 Mon Sep 17 00:00:00 2001 From: Markov Date: Mon, 23 Feb 2026 18:43:40 +0100 Subject: [PATCH] fix: connect WebSocket on auth, subscribe to project events --- src/app/(protected)/projects/[slug]/page.tsx | 9 +++++++++ src/components/AuthGuard.tsx | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/src/app/(protected)/projects/[slug]/page.tsx b/src/app/(protected)/projects/[slug]/page.tsx index cb4f881..832ee4d 100644 --- a/src/app/(protected)/projects/[slug]/page.tsx +++ b/src/app/(protected)/projects/[slug]/page.tsx @@ -3,6 +3,7 @@ import { useEffect, useState } from "react"; import { useParams } from "next/navigation"; import { getProjects, Project } from "@/lib/api"; +import { wsClient } from "@/lib/ws"; import Sidebar from "@/components/Sidebar"; import KanbanBoard from "@/components/KanbanBoard"; import ChatPanel from "@/components/ChatPanel"; @@ -31,6 +32,14 @@ export default function ProjectPage() { const project = projects.find((p) => p.slug === slug); + // Subscribe to project WS events + useEffect(() => { + if (project?.id) { + wsClient.subscribeProject(project.id); + return () => wsClient.unsubscribeProject(project.id); + } + }, [project?.id]); + const handleProjectUpdated = (updated: Project) => { setProjects((prev) => prev.map((p) => (p.id === updated.id ? updated : p))); }; diff --git a/src/components/AuthGuard.tsx b/src/components/AuthGuard.tsx index fbadf48..fbfa7a7 100644 --- a/src/components/AuthGuard.tsx +++ b/src/components/AuthGuard.tsx @@ -3,6 +3,7 @@ import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { isAuthenticated } from "@/lib/auth-client"; +import { wsClient } from "@/lib/ws"; export default function AuthGuard({ children }: { children: React.ReactNode }) { const router = useRouter(); @@ -13,7 +14,14 @@ export default function AuthGuard({ children }: { children: React.ReactNode }) { router.replace("/login"); } else { setChecked(true); + // Connect WebSocket after auth check + if (!wsClient.connected) { + wsClient.connect(); + } } + return () => { + // Don't disconnect on unmount — singleton stays alive + }; }, [router]); if (!checked) {