--ADDED JWT SECURITY TO WEBSOCKET
This commit is contained in:
george committed 2026-09-24 18:09:36 +05:30
1 parent cdf5f51e65
commit 83d065c530
3 files changed
+20 -3

No files matched your search

+8 -1
View File
@@ -44,6 +44,11 @@ export default function NodeConnections({ nodeId }: { nodeId: string }) {
if (!baseUrl) throw new Error('VITE_WS_BASE_URL is not configured.')
const token = localStorage.getItem('access_token')
if (!token) {
throw new Error(
'Authentication required. Please log in again.'
)
}
const response = await fetch(
`${apiBaseUrl.replace(/\/$/, '')}/spock/node-interfaces/${encodeURIComponent(nodeId)}`,
{
@@ -69,8 +74,10 @@ export default function NodeConnections({ nodeId }: { nodeId: string }) {
}
if (!active) return
const wstoken = token
if (!wstoken) throw new Error('Authentication required. Get a token from the Nodes page, then reconnect.')
setStatus('Connecting to replication health…')
const connection = new WebSocket(`${baseUrl.replace(/\/$/, '')}/ws/node/replication-health`)
const connection = new WebSocket(`${baseUrl.replace(/\/$/, '')}/ws/node/replication-health?token=${encodeURIComponent(wstoken)}`)
socket = connection
connection.onopen = () => {
if (!active) return
+6 -1
View File
@@ -61,7 +61,12 @@ export default function useDatabaseStatus(nodeId: string, nodeName: string) {
}
if (!active) return
setConnection('Connecting…')
const current = new WebSocket(`${wsBaseUrl.replace(/\/$/, '')}/ws/database/status`)
const wstoken = token
if (!wstoken?.trim()) {
setConnection('Connection skipped: JWT URL parameter required')
return
}
const current = new WebSocket(`${wsBaseUrl.replace(/\/$/, '')}/ws/database/status?token=${encodeURIComponent(wstoken)}`)
socket = current
current.onopen = () => {
if (!active) return
+6 -1
View File
@@ -51,7 +51,12 @@ export default function useNodeDatabaseMetric<T>(
}
if (!active) return
setConnection('Connecting…')
const current = new WebSocket(`${wsBaseUrl.replace(/\/$/, '')}/ws/database/${endpoint}`)
const wstoken = token
if (!wstoken?.trim()) {
setConnection('Connection skipped: JWT URL parameter required')
return
}
const current = new WebSocket(`${wsBaseUrl.replace(/\/$/, '')}/ws/database/${endpoint}?token=${encodeURIComponent(wstoken)}`)
socket = current
current.onopen = () => {
if (!active) return