⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix: redirect revoked workspace settings sessions
Tinc97de54212b3
diff --git a/apps/web/src/hooks/use-user-websocket-lifecycle.test.tsx b/apps/web/src/hooks/use-user-websocket-lifecycle.test.tsxindex c2b174e91..a9e064446 100644--- a/apps/web/src/hooks/use-user-websocket-lifecycle.test.tsx+++ b/apps/web/src/hooks/use-user-websocket-lifecycle.test.tsx@@ -18,17 +18,27 @@ const { client, auth, navigate } = vi.hoisted(() => ({removeQueries: vi.fn(),},navigate: vi.fn(),- auth: { userId: "user-a" as string | null, workspaceId: "workspace" },+ auth: {+ userId: "user-a" as string | null,+ workspaceId: "workspace",+ pathname: "",+ },}));vi.mock("@tanstack/react-router", () => ({useNavigate: () => navigate,- useLocation: () => `/dashboard/workspace/${auth.workspaceId}`,+ useLocation: () =>+ auth.pathname || `/dashboard/workspace/${auth.workspaceId}`,}));vi.mock("@tanstack/react-query", () => ({ useQueryClient: () => client }));vi.mock("@/lib/auth-client", () => ({authClient: {useSession: () => ({- data: auth.userId ? { user: { id: auth.userId } } : null,+ data: auth.userId+ ? {+ user: { id: auth.userId },+ session: { activeOrganizationId: auth.workspaceId },+ }+ : null,}),},}));@@ -60,6 +70,7 @@ describe("user WebSocket lifecycle", () => {TestSocket.instances = [];auth.userId = "user-a";auth.workspaceId = "workspace";+ auth.pathname = "";vi.clearAllMocks();});afterEach(() => {@@ -68,6 +79,23 @@ describe("user WebSocket lifecycle", () => {vi.unstubAllGlobals();vi.unstubAllEnvs();});+ it.each([+ "/dashboard/settings/workspace/general",+ "/dashboard/settings/workspace/roles",+ "/dashboard/settings/projects/general",+ ])("redirects a revoked active workspace from %s", (path) => {+ auth.pathname = path;+ renderHook(useUserWebSocket);+ act(() =>+ TestSocket.instances[0].onmessage?.({+ data: JSON.stringify({+ type: "WORKSPACE_ACCESS_REVOKED",+ workspaceId: "workspace",+ }),+ }),+ );+ expect(navigate).toHaveBeenCalledWith({ to: "/dashboard" });+ });it("clears revoked workspace data from the global user connection", () => {renderHook(() => useUserWebSocket());act(() =>@@ -75,6 +103,7 @@ describe("user WebSocket lifecycle", () => {data: JSON.stringify({type: "WORKSPACE_ACCESS_REVOKED",workspaceId: "workspace",+ pathname: "",}),}),);@@ -165,6 +194,7 @@ describe("user WebSocket lifecycle", () => {data: JSON.stringify({type: "WORKSPACE_ACCESS_REVOKED",workspaceId: "workspace",+ pathname: "",}),});expect(navigate).not.toHaveBeenCalled();diff --git a/apps/web/src/hooks/use-user-websocket.ts b/apps/web/src/hooks/use-user-websocket.tsindex 5cbcb3bc1..bf1e33310 100644--- a/apps/web/src/hooks/use-user-websocket.ts+++ b/apps/web/src/hooks/use-user-websocket.ts@@ -28,6 +28,8 @@ export function useUserWebSocket() {const pathnameRef = useRef(pathname);pathnameRef.current = pathname;const { data: session } = authClient.useSession();+ const activeWorkspaceRef = useRef(session?.session?.activeOrganizationId);+ activeWorkspaceRef.current = session?.session?.activeOrganizationId;useEffect(() => {if (!session?.user?.id) return;@@ -75,8 +77,11 @@ export function useUserWebSocket() {message.workspaceId) {evictWorkspaceCache(queryClient, message.workspaceId);+ const path = pathnameRef.current;const current =- pathnameRef.current.match(/\/workspace\/([^/]+)/)?.[1];+ /^\/dashboard\/settings\/(workspace|projects)(\/|$)/.test(path)+ ? activeWorkspaceRef.current+ : path.match(/^\/dashboard\/workspace\/([^/]+)/)?.[1];if (current === message.workspaceId)void navigate({ to: "/dashboard" });}