Retro Bulletin Board Systems on atproto. Web app and TUI. lazy mirror of alyraffauf/atbbs atbbs.xyz
forums python tui atproto bbs
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

web/lib/auth: store handle in localStorage

+31 -2
+31 -2
web/src/lib/auth.ts
··· 71 71 type Did = `did:${string}:${string}`; 72 72 73 73 const CURRENT_DID_KEY = "atbbs:current-did"; 74 + const CURRENT_HANDLE_KEY = "atbbs:current-handle"; 74 75 const POST_LOGIN_KEY = "atbbs:post-login-redirect"; 75 76 76 77 // --- Module-level auth state --- ··· 104 105 const rpc = new Client({ handler: oauthAgent }); 105 106 const did = oauthAgent.sub; 106 107 107 - let handle: string = did; 108 + // Fall back to the last-known handle (if any) so offline restores don't 109 + // show a raw DID in the header. Gets overwritten once Slingshot responds. 110 + let handle = localStorage.getItem(CURRENT_HANDLE_KEY) ?? did; 108 111 let pdsUrl = ""; 109 112 try { 110 113 const doc = await resolveIdentity(did); 111 114 handle = doc.handle; 112 115 pdsUrl = doc.pds ?? ""; 116 + localStorage.setItem(CURRENT_HANDLE_KEY, handle); 113 117 } catch { 114 - // best-effort — falls back to showing the raw DID 118 + // Network may be unavailable (e.g., just resumed from suspend). We'll 119 + // retry on the next tab focus via the visibilitychange listener below. 115 120 } 116 121 117 122 currentAgent = rpc; ··· 123 128 } catch { 124 129 // storage full or blocked — non-fatal 125 130 } 131 + } 132 + 133 + async function retryIdentityIfUnresolved() { 134 + if (!currentUser) return; 135 + if (currentUser.handle !== currentUser.did) return; 136 + try { 137 + const doc = await resolveIdentity(currentUser.did); 138 + currentUser = { 139 + did: currentUser.did, 140 + handle: doc.handle, 141 + pdsUrl: doc.pds ?? currentUser.pdsUrl, 142 + }; 143 + localStorage.setItem(CURRENT_HANDLE_KEY, doc.handle); 144 + notifyListeners(); 145 + } catch { 146 + // still offline; next focus will try again 147 + } 148 + } 149 + 150 + if (typeof document !== "undefined") { 151 + document.addEventListener("visibilitychange", () => { 152 + if (document.visibilityState === "visible") retryIdentityIfUnresolved(); 153 + }); 126 154 } 127 155 128 156 function setSignedOut() { ··· 246 274 } 247 275 try { 248 276 localStorage.removeItem(CURRENT_DID_KEY); 277 + localStorage.removeItem(CURRENT_HANDLE_KEY); 249 278 } catch { 250 279 // non-fatal 251 280 }