mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 21:46:49 +00:00
fix(realtime): open no socket after a logout, and reconnect as soon as the network is back
A connect still waiting for its ws token when the user logged out went on to open a socket authenticated as that user, which the next login on the same browser then reused. And a socket in its reconnect backoff waited up to 30 s after the network came back or the tab became visible. Both events now reconnect right away.
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
import { mutationQueue } from './mutationQueue'
|
||||
import { tripSyncManager } from './tripSyncManager'
|
||||
import { isEffectivelyOnline, onNetworkModeChange } from './networkMode'
|
||||
import { setPreReconnectHook, setRefetchCallback, getActiveTrips } from '../api/websocket'
|
||||
import { setPreReconnectHook, setRefetchCallback, getActiveTrips, reconnectNow } from '../api/websocket'
|
||||
import { useTripStore } from '../store/tripStore'
|
||||
import { useSettingsStore } from '../store/settingsStore'
|
||||
import { useAuthStore } from '../store/authStore'
|
||||
@@ -61,6 +61,7 @@ function onOnline() {
|
||||
// routes through onNetworkMode → here with the force flag already cleared).
|
||||
if (!isEffectivelyOnline()) return
|
||||
ensureSettingsLoaded()
|
||||
reconnectNow()
|
||||
mutationQueue.flush()
|
||||
.catch(console.error)
|
||||
.finally(() => {
|
||||
@@ -73,6 +74,7 @@ function onOnline() {
|
||||
function onVisibility() {
|
||||
if (!document.hidden && isEffectivelyOnline()) {
|
||||
ensureSettingsLoaded()
|
||||
reconnectNow()
|
||||
mutationQueue.flush().catch(console.error)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user