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>;
|
||||
#syncState: SyncState;
|
||||
#ws: WebSocket | null = null;
|
||||
#disconnectedIntentionally = false;
|
||||
#communitySlug: string;
|
||||
#shapes: Map<string, FolkShape> = new Map();
|
||||
#pendingChanges: boolean = false;
|
||||
|
|
@ -228,8 +229,9 @@ export class CommunitySync extends EventTarget {
|
|||
console.log(`[CommunitySync] Disconnected from ${this.#communitySlug}`);
|
||||
this.dispatchEvent(new CustomEvent("disconnected"));
|
||||
|
||||
// Attempt reconnect
|
||||
this.#attemptReconnect(wsUrl);
|
||||
if (!this.#disconnectedIntentionally) {
|
||||
this.#attemptReconnect(wsUrl);
|
||||
}
|
||||
};
|
||||
|
||||
this.#ws.onerror = (error) => {
|
||||
|
|
@ -1134,6 +1136,7 @@ export class CommunitySync extends EventTarget {
|
|||
* Disconnect from server
|
||||
*/
|
||||
disconnect(): void {
|
||||
this.#disconnectedIntentionally = true;
|
||||
if (this.#ws) {
|
||||
this.#ws.close();
|
||||
this.#ws = null;
|
||||
|
|
|
|||
|
|
@ -1346,6 +1346,13 @@
|
|||
document.addEventListener("auth-change", () => {
|
||||
const sw = document.querySelector("rstack-space-switcher");
|
||||
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
|
||||
|
|
@ -1677,6 +1684,7 @@
|
|||
const offlineStore = new OfflineStore();
|
||||
await offlineStore.open();
|
||||
const sync = new CommunitySync(communitySlug, offlineStore);
|
||||
window.__communitySync = sync;
|
||||
|
||||
// Try to load from cache immediately (shows content before WebSocket connects)
|
||||
const hadCache = await sync.initFromCache();
|
||||
|
|
|
|||
|
|
@ -32,4 +32,10 @@ RStackMi.define();
|
|||
document.addEventListener("auth-change", () => {
|
||||
const spaceSwitcher = document.querySelector("rstack-space-switcher") as any;
|
||||
spaceSwitcher?.reload?.();
|
||||
|
||||
// If signed out, redirect to homepage
|
||||
const session = localStorage.getItem("encryptid_session");
|
||||
if (!session) {
|
||||
window.location.href = "/";
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue