Skip to content

A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.

feat(app): token in EventSource

dextmorgn408ce3af510e
diff --git a/flowsint-app/src/hooks/use-events.ts b/flowsint-app/src/hooks/use-events.ts
index 533aa5b0..eeea0e3f 100644
--- a/flowsint-app/src/hooks/use-events.ts
+++ b/flowsint-app/src/hooks/use-events.ts
@@ -2,12 +2,14 @@ import { useEffect, useState, useMemo } from 'react'
import { useQuery } from '@tanstack/react-query'
import { logService } from '@/api/log-service'
import { queryKeys } from '@/api/query-keys'
+import { useAuthStore } from '@/stores/auth-store'
const API_URL = import.meta.env.VITE_API_URL
export function useEvents(sketch_id: string | undefined) {
const [liveLogs, setLiveLogs] = useState<Event[]>([])
+ const token = useAuthStore((s) => s.token)
const { data: previousLogs = [], refetch } = useQuery({
queryKey: queryKeys.logs.bySketch(sketch_id as string),
@@ -26,10 +28,10 @@ export function useEvents(sketch_id: string | undefined) {
}, [sketch_id])
useEffect(() => {
- if (!sketch_id) return
+ if (!sketch_id || !token) return
const eventSource = new EventSource(
- `${API_URL}/api/events/sketch/${sketch_id}/stream`
+ `${API_URL}/api/events/sketch/${sketch_id}/stream?token=${token}`
)
eventSource.onmessage = (e) => {
@@ -67,7 +69,7 @@ export function useEvents(sketch_id: string | undefined) {
return () => {
eventSource.close()
}
- }, [sketch_id])
+ }, [sketch_id, token])
const logs = useMemo(
() => [...previousLogs, ...liveLogs].slice(-100),
diff --git a/flowsint-app/src/hooks/use-graph-refresh.ts b/flowsint-app/src/hooks/use-graph-refresh.ts
index 0415755d..80ae9883 100644
--- a/flowsint-app/src/hooks/use-graph-refresh.ts
+++ b/flowsint-app/src/hooks/use-graph-refresh.ts
@@ -1,5 +1,6 @@
import { useEffect, useRef } from 'react'
import { useGraphControls } from '@/stores/graph-controls-store'
+import { useAuthStore } from '@/stores/auth-store'
import { EventLevel } from '@/types'
const API_URL = import.meta.env.VITE_API_URL
@@ -8,6 +9,7 @@ export function useGraphRefresh(sketch_id: string | undefined) {
const refetchGraph = useGraphControls((s) => s.refetchGraph)
const regenerateLayout = useGraphControls((s) => s.regenerateLayout)
const currentLayoutType = useGraphControls((s) => s.currentLayoutType)
+ const token = useAuthStore((s) => s.token)
// Use refs to avoid reconnecting SSE when functions change
const refetchGraphRef = useRef(refetchGraph)
@@ -22,9 +24,9 @@ export function useGraphRefresh(sketch_id: string | undefined) {
}, [refetchGraph, regenerateLayout, currentLayoutType])
useEffect(() => {
- if (!sketch_id) return
+ if (!sketch_id || !token) return
const eventSource = new EventSource(
- `${API_URL}/api/events/sketch/${sketch_id}/status/stream`
+ `${API_URL}/api/events/sketch/${sketch_id}/status/stream?token=${token}`
)
eventSource.onmessage = (e) => {
try {
@@ -73,5 +75,5 @@ export function useGraphRefresh(sketch_id: string | undefined) {
return () => {
eventSource.close()
}
- }, [sketch_id]) // Only reconnect when sketch_id changes
+ }, [sketch_id, token]) // Only reconnect when sketch_id or token changes
}