@pylonsync/sync 0.5.2 → 0.5.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/index.d.ts +8 -3
- package/package.json +1 -1
- package/src/index.ts +20 -8
package/dist/index.d.ts
CHANGED
|
@@ -733,9 +733,14 @@ export declare class SyncEngine {
|
|
|
733
733
|
* origin (every app on localhost:4321 in dev) both read the default,
|
|
734
734
|
* unprefixed `pylon_token`, so one app sends the other's token and the
|
|
735
735
|
* server rejects it. The failure surfaces far away as "anonymous session"
|
|
736
|
-
* from createOrg, which names neither the token nor the keyspace.
|
|
737
|
-
*
|
|
738
|
-
*
|
|
736
|
+
* from createOrg, which names neither the token nor the keyspace.
|
|
737
|
+
*
|
|
738
|
+
* Heal it here instead of "on next login": clear the app's OWN namespaced
|
|
739
|
+
* token so the invalid value stops being sent and the app drops cleanly to
|
|
740
|
+
* signed-out (a real sign-in then writes a valid token into this namespace).
|
|
741
|
+
* Only the namespaced key — never the shared default `pylon_token`, which may
|
|
742
|
+
* belong to a different app on this origin. Warn once so the cause is named.
|
|
743
|
+
* A genuinely signed-out user has no stored token, so this stays quiet.
|
|
739
744
|
*/
|
|
740
745
|
private warnForeignToken;
|
|
741
746
|
/**
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -2396,21 +2396,33 @@ export class SyncEngine {
|
|
|
2396
2396
|
* origin (every app on localhost:4321 in dev) both read the default,
|
|
2397
2397
|
* unprefixed `pylon_token`, so one app sends the other's token and the
|
|
2398
2398
|
* server rejects it. The failure surfaces far away as "anonymous session"
|
|
2399
|
-
* from createOrg, which names neither the token nor the keyspace.
|
|
2400
|
-
*
|
|
2401
|
-
*
|
|
2399
|
+
* from createOrg, which names neither the token nor the keyspace.
|
|
2400
|
+
*
|
|
2401
|
+
* Heal it here instead of "on next login": clear the app's OWN namespaced
|
|
2402
|
+
* token so the invalid value stops being sent and the app drops cleanly to
|
|
2403
|
+
* signed-out (a real sign-in then writes a valid token into this namespace).
|
|
2404
|
+
* Only the namespaced key — never the shared default `pylon_token`, which may
|
|
2405
|
+
* belong to a different app on this origin. Warn once so the cause is named.
|
|
2406
|
+
* A genuinely signed-out user has no stored token, so this stays quiet.
|
|
2402
2407
|
*/
|
|
2403
2408
|
private warnForeignToken(): void {
|
|
2404
2409
|
if (this.warnedForeignToken) return;
|
|
2405
2410
|
if (this.config.token) return; // explicit token, not a keyspace artifact
|
|
2406
|
-
|
|
2411
|
+
const key = this.tokenStorageKey();
|
|
2412
|
+
if (!this.storage.get(key)) return; // no token → normal signed-out
|
|
2407
2413
|
this.warnedForeignToken = true;
|
|
2414
|
+
if (key !== "pylon_token") {
|
|
2415
|
+
// Self-heal: drop the rejected token from this app's namespace so the
|
|
2416
|
+
// next request doesn't resend it. Leaves the ambiguous default key alone.
|
|
2417
|
+
this.storage.remove(key);
|
|
2418
|
+
this.storage.remove(key.replace(/:token$/, ":userId"));
|
|
2419
|
+
}
|
|
2408
2420
|
console.warn(
|
|
2409
2421
|
'[pylon] a stored auth token was rejected (/api/auth/me resolved to an ' +
|
|
2410
|
-
'anonymous identity)
|
|
2411
|
-
'
|
|
2412
|
-
"other's sessions. Give each
|
|
2413
|
-
"configureClient({ appName }).",
|
|
2422
|
+
'anonymous identity) and has been cleared from this app. If more than ' +
|
|
2423
|
+
'one Pylon app runs on this origin, they share the default ' +
|
|
2424
|
+
'"pylon_token" keyspace and clobber each other\'s sessions. Give each ' +
|
|
2425
|
+
"app a name: init({ appName }) / configureClient({ appName }).",
|
|
2414
2426
|
);
|
|
2415
2427
|
}
|
|
2416
2428
|
|