fix: connect WebSocket on auth, subscribe to project events
All checks were successful
Deploy Web Client / deploy (push) Successful in 36s
All checks were successful
Deploy Web Client / deploy (push) Successful in 36s
This commit is contained in:
parent
c37d9aed15
commit
307027faae
@ -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)));
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user