fix: connect WebSocket on auth, subscribe to project events
All checks were successful
Deploy Web Client / deploy (push) Successful in 36s

This commit is contained in:
Markov 2026-02-23 18:43:40 +01:00
parent c37d9aed15
commit 307027faae
2 changed files with 17 additions and 0 deletions

View File

@ -3,6 +3,7 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useParams } from "next/navigation"; import { useParams } from "next/navigation";
import { getProjects, Project } from "@/lib/api"; import { getProjects, Project } from "@/lib/api";
import { wsClient } from "@/lib/ws";
import Sidebar from "@/components/Sidebar"; import Sidebar from "@/components/Sidebar";
import KanbanBoard from "@/components/KanbanBoard"; import KanbanBoard from "@/components/KanbanBoard";
import ChatPanel from "@/components/ChatPanel"; import ChatPanel from "@/components/ChatPanel";
@ -31,6 +32,14 @@ export default function ProjectPage() {
const project = projects.find((p) => p.slug === slug); 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) => { const handleProjectUpdated = (updated: Project) => {
setProjects((prev) => prev.map((p) => (p.id === updated.id ? updated : p))); setProjects((prev) => prev.map((p) => (p.id === updated.id ? updated : p)));
}; };

View File

@ -3,6 +3,7 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { isAuthenticated } from "@/lib/auth-client"; import { isAuthenticated } from "@/lib/auth-client";
import { wsClient } from "@/lib/ws";
export default function AuthGuard({ children }: { children: React.ReactNode }) { export default function AuthGuard({ children }: { children: React.ReactNode }) {
const router = useRouter(); const router = useRouter();
@ -13,7 +14,14 @@ export default function AuthGuard({ children }: { children: React.ReactNode }) {
router.replace("/login"); router.replace("/login");
} else { } else {
setChecked(true); setChecked(true);
// Connect WebSocket after auth check
if (!wsClient.connected) {
wsClient.connect();
}
} }
return () => {
// Don't disconnect on unmount — singleton stays alive
};
}, [router]); }, [router]);
if (!checked) { if (!checked) {