@nebulr-group/bridge-svelte 0.4.0-beta.3 → 0.4.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/bridge-runtime.js +20 -1
- package/package.json +2 -2
|
@@ -104,6 +104,10 @@ export function startBridgeRuntime(options = {}) {
|
|
|
104
104
|
getAuthToken: () => _currentAuthToken,
|
|
105
105
|
});
|
|
106
106
|
let _connectedOnce = false;
|
|
107
|
+
// Set just before we call _realtime.reauthorize() so the resulting
|
|
108
|
+
// reconnect's setOnOpen handler knows the token is already fresh and skips
|
|
109
|
+
// its proactive refresh — see the loop note in setOnOpen below.
|
|
110
|
+
let _reauthInFlight = false;
|
|
107
111
|
_realtime.setOnOpen(() => {
|
|
108
112
|
_setRealtimeStatus('open');
|
|
109
113
|
// On reconnect (not initial connect), proactively refresh tokens.
|
|
@@ -111,7 +115,18 @@ export function startBridgeRuntime(options = {}) {
|
|
|
111
115
|
// client missed the user.state_changed broadcast. Refreshing here
|
|
112
116
|
// syncs tokens before the first post-reconnect request can fail with
|
|
113
117
|
// TOKEN_VERSION_STALE.
|
|
114
|
-
|
|
118
|
+
//
|
|
119
|
+
// EXCEPT when this reconnect was caused by our OWN reauthorize() below
|
|
120
|
+
// (a token-only refresh). In that case the token is already current, so
|
|
121
|
+
// refreshing again would mint yet another JWT, which the tokenStore
|
|
122
|
+
// subscription would see as a change and reauthorize() again → reconnect
|
|
123
|
+
// → setOnOpen → refresh → … an unbounded loop that hammers /auth/token
|
|
124
|
+
// (observed ~32 cycles/sec, jamming the page's main thread and stalling
|
|
125
|
+
// every downstream wait). Only genuine, externally-triggered reconnects
|
|
126
|
+
// (network blips, server restarts) should trigger the catch-up refresh.
|
|
127
|
+
const causedByReauthorize = _reauthInFlight;
|
|
128
|
+
_reauthInFlight = false;
|
|
129
|
+
if (_connectedOnce && !causedByReauthorize) {
|
|
115
130
|
getBridgeAuth().refreshTokens().catch(() => { });
|
|
116
131
|
}
|
|
117
132
|
_connectedOnce = true;
|
|
@@ -224,6 +239,10 @@ export function startBridgeRuntime(options = {}) {
|
|
|
224
239
|
// Centrifugo's connection-token TTL drops it. Force a reauthorize so the
|
|
225
240
|
// server re-validates against the new token immediately.
|
|
226
241
|
if (prevAuthToken && _currentAuthToken && prevAuthToken !== _currentAuthToken) {
|
|
242
|
+
// Flag this as a self-induced reconnect so setOnOpen does NOT fire its
|
|
243
|
+
// proactive refresh (which would mint a new token → land back here →
|
|
244
|
+
// loop forever). The token we're reauthorizing with is already current.
|
|
245
|
+
_reauthInFlight = true;
|
|
227
246
|
void _realtime.reauthorize();
|
|
228
247
|
}
|
|
229
248
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nebulr-group/bridge-svelte",
|
|
3
|
-
"version": "0.4.0-beta.
|
|
3
|
+
"version": "0.4.0-beta.4",
|
|
4
4
|
"description": "Bridge Svelte library, This library helps you to add bridge authentication and feature flags, and payments to your svelte application.",
|
|
5
5
|
"author": "Iman Pouya",
|
|
6
6
|
"license": "MIT",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
}
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@nebulr-group/bridge-auth-core": "0.4.0-beta.
|
|
70
|
+
"@nebulr-group/bridge-auth-core": "0.4.0-beta.5"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@sveltejs/kit": "^2.16.0",
|