fix: disconnect from spaces and redirect on EncryptID sign-out
Prevents stale WebSocket reconnect loops after sign-out by adding an intentional-disconnect flag to CommunitySync. Canvas and shell pages now redirect to homepage when the user signs out. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e7f9507d9d
commit
b252004f48
|
|
@ -109,6 +109,7 @@ export class CommunitySync extends EventTarget {
|
||||||
#doc: Automerge.Doc<CommunityDoc>;
|
#doc: Automerge.Doc<CommunityDoc>;
|
||||||
#syncState: SyncState;
|
#syncState: SyncState;
|
||||||
#ws: WebSocket | null = null;
|
#ws: WebSocket | null = null;
|
||||||
|
#disconnectedIntentionally = false;
|
||||||
#communitySlug: string;
|
#communitySlug: string;
|
||||||
#shapes: Map<string, FolkShape> = new Map();
|
#shapes: Map<string, FolkShape> = new Map();
|
||||||
#pendingChanges: boolean = false;
|
#pendingChanges: boolean = false;
|
||||||
|
|
@ -228,8 +229,9 @@ export class CommunitySync extends EventTarget {
|
||||||
console.log(`[CommunitySync] Disconnected from ${this.#communitySlug}`);
|
console.log(`[CommunitySync] Disconnected from ${this.#communitySlug}`);
|
||||||
this.dispatchEvent(new CustomEvent("disconnected"));
|
this.dispatchEvent(new CustomEvent("disconnected"));
|
||||||
|
|
||||||
// Attempt reconnect
|
if (!this.#disconnectedIntentionally) {
|
||||||
this.#attemptReconnect(wsUrl);
|
this.#attemptReconnect(wsUrl);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.#ws.onerror = (error) => {
|
this.#ws.onerror = (error) => {
|
||||||
|
|
@ -1134,6 +1136,7 @@ export class CommunitySync extends EventTarget {
|
||||||
* Disconnect from server
|
* Disconnect from server
|
||||||
*/
|
*/
|
||||||
disconnect(): void {
|
disconnect(): void {
|
||||||
|
this.#disconnectedIntentionally = true;
|
||||||
if (this.#ws) {
|
if (this.#ws) {
|
||||||
this.#ws.close();
|
this.#ws.close();
|
||||||
this.#ws = null;
|
this.#ws = null;
|
||||||
|
|
|
||||||
|
|
@ -1346,6 +1346,13 @@
|
||||||
document.addEventListener("auth-change", () => {
|
document.addEventListener("auth-change", () => {
|
||||||
const sw = document.querySelector("rstack-space-switcher");
|
const sw = document.querySelector("rstack-space-switcher");
|
||||||
sw?.reload?.();
|
sw?.reload?.();
|
||||||
|
|
||||||
|
// If signed out, disconnect from space and go home
|
||||||
|
const session = localStorage.getItem("encryptid_session");
|
||||||
|
if (!session) {
|
||||||
|
window.__communitySync?.disconnect?.();
|
||||||
|
window.location.href = "/";
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Load module list for app switcher and tab bar + menu
|
// Load module list for app switcher and tab bar + menu
|
||||||
|
|
@ -1677,6 +1684,7 @@
|
||||||
const offlineStore = new OfflineStore();
|
const offlineStore = new OfflineStore();
|
||||||
await offlineStore.open();
|
await offlineStore.open();
|
||||||
const sync = new CommunitySync(communitySlug, offlineStore);
|
const sync = new CommunitySync(communitySlug, offlineStore);
|
||||||
|
window.__communitySync = sync;
|
||||||
|
|
||||||
// Try to load from cache immediately (shows content before WebSocket connects)
|
// Try to load from cache immediately (shows content before WebSocket connects)
|
||||||
const hadCache = await sync.initFromCache();
|
const hadCache = await sync.initFromCache();
|
||||||
|
|
|
||||||
|
|
@ -32,4 +32,10 @@ RStackMi.define();
|
||||||
document.addEventListener("auth-change", () => {
|
document.addEventListener("auth-change", () => {
|
||||||
const spaceSwitcher = document.querySelector("rstack-space-switcher") as any;
|
const spaceSwitcher = document.querySelector("rstack-space-switcher") as any;
|
||||||
spaceSwitcher?.reload?.();
|
spaceSwitcher?.reload?.();
|
||||||
|
|
||||||
|
// If signed out, redirect to homepage
|
||||||
|
const session = localStorage.getItem("encryptid_session");
|
||||||
|
if (!session) {
|
||||||
|
window.location.href = "/";
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue