feat:
--ADDED JWT SECURITY TO WEBSOCKET
This commit is contained in:
1 parent
cdf5f51e65
commit
83d065c530
3 files changed
+20
-3
No files matched your search
@@ -44,6 +44,11 @@ export default function NodeConnections({ nodeId }: { nodeId: string }) {
|
|||||||
if (!baseUrl) throw new Error('VITE_WS_BASE_URL is not configured.')
|
if (!baseUrl) throw new Error('VITE_WS_BASE_URL is not configured.')
|
||||||
|
|
||||||
const token = localStorage.getItem('access_token')
|
const token = localStorage.getItem('access_token')
|
||||||
|
if (!token) {
|
||||||
|
throw new Error(
|
||||||
|
'Authentication required. Please log in again.'
|
||||||
|
)
|
||||||
|
}
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${apiBaseUrl.replace(/\/$/, '')}/spock/node-interfaces/${encodeURIComponent(nodeId)}`,
|
`${apiBaseUrl.replace(/\/$/, '')}/spock/node-interfaces/${encodeURIComponent(nodeId)}`,
|
||||||
{
|
{
|
||||||
@@ -69,8 +74,10 @@ export default function NodeConnections({ nodeId }: { nodeId: string }) {
|
|||||||
}
|
}
|
||||||
if (!active) return
|
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…')
|
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
|
socket = connection
|
||||||
connection.onopen = () => {
|
connection.onopen = () => {
|
||||||
if (!active) return
|
if (!active) return
|
||||||
|
|||||||
@@ -61,7 +61,12 @@ export default function useDatabaseStatus(nodeId: string, nodeName: string) {
|
|||||||
}
|
}
|
||||||
if (!active) return
|
if (!active) return
|
||||||
setConnection('Connecting…')
|
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
|
socket = current
|
||||||
current.onopen = () => {
|
current.onopen = () => {
|
||||||
if (!active) return
|
if (!active) return
|
||||||
|
|||||||
@@ -51,7 +51,12 @@ export default function useNodeDatabaseMetric<T>(
|
|||||||
}
|
}
|
||||||
if (!active) return
|
if (!active) return
|
||||||
setConnection('Connecting…')
|
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
|
socket = current
|
||||||
current.onopen = () => {
|
current.onopen = () => {
|
||||||
if (!active) return
|
if (!active) return
|
||||||
|
|||||||
Reference in new issue
Block a user