diff --git a/src/client/api/socketio.ts b/src/client/api/socketio.ts index 5508954..8439628 100644 --- a/src/client/api/socketio.ts +++ b/src/client/api/socketio.ts @@ -4,6 +4,7 @@ import type { SubscribeEventMap, SocketEventMap } from '../../server/ws/shared'; import { create } from 'zustand'; import { useEvent } from '../hooks/useEvent'; import { useEffect, useReducer, useState } from 'react'; +import { useIsLogined, useUserInfo } from '../store/user'; const useSocketStore = create<{ socket: Socket | null; @@ -120,6 +121,7 @@ export function useSocketSubscribeList< >(name: K, options: UseSocketSubscribeListOptions = {}): T[] { const { filter = defaultFilter } = options; const { subscribe } = useSocket(); + const isLogined = useIsLogined(); const [list, push] = useReducer( (state: T[], data: T) => [...state, data], [] as T[] @@ -132,6 +134,11 @@ export function useSocketSubscribeList< }); useEffect(() => { + if (!isLogined) { + console.warn('Skip socket subscribe login because of not login'); + return; + } + const unsubscribe = subscribe(name, cb); return () => { diff --git a/src/client/components/monitor/MonitorListItem.tsx b/src/client/components/monitor/MonitorListItem.tsx index ecbd1ca..b8321f3 100644 --- a/src/client/components/monitor/MonitorListItem.tsx +++ b/src/client/components/monitor/MonitorListItem.tsx @@ -37,7 +37,8 @@ export const MonitorListItem: React.FC<{
diff --git a/src/client/components/monitor/StatusPage/Services.tsx b/src/client/components/monitor/StatusPage/Services.tsx index 85314d7..50a69d4 100644 --- a/src/client/components/monitor/StatusPage/Services.tsx +++ b/src/client/components/monitor/StatusPage/Services.tsx @@ -24,13 +24,12 @@ export const StatusPageServices: React.FC = React.memo(
{list.length > 0 ? ( list.map((item) => ( -
- -
+ )) ) : ( diff --git a/src/client/store/user.ts b/src/client/store/user.ts index 710dae6..a3daea4 100644 --- a/src/client/store/user.ts +++ b/src/client/store/user.ts @@ -35,6 +35,10 @@ export function useUserInfo(): UserLoginInfo | null { return useUserStore((state) => state.info); } +export function useIsLogined() { + return !!useUserInfo(); +} + export function useCurrentWorkspace() { const currentWorkspace = useUserStore( (state) => state.info?.currentWorkspace diff --git a/src/server/trpc/routers/monitor.ts b/src/server/trpc/routers/monitor.ts index 8cdf0f1..3bac342 100644 --- a/src/server/trpc/routers/monitor.ts +++ b/src/server/trpc/routers/monitor.ts @@ -256,15 +256,18 @@ export const monitorRouter = router({ return monitor; }), - recentData: workspaceProcedure - .meta( - buildMonitorOpenapi({ + recentData: publicProcedure + .meta({ + openapi: { + tags: [OPENAPI_TAG.MONITOR], + protect: false, method: 'GET', - path: '/{monitorId}/recentData', - }) - ) + path: `/monitor/{monitorId}/recentData`, + }, + }) .input( z.object({ + workspaceId: z.string().cuid2(), monitorId: z.string().cuid2(), take: z.number(), })