From 6818fb418ff977f13a6e6a0de67feea4f5443e84 Mon Sep 17 00:00:00 2001 From: phil Date: Tue, 15 Jul 2025 11:49:03 -0400 Subject: [PATCH] log out --- .../src/components/setup/Chrome.tsx | 5 +-- .../src/components/setup/WithServerHello.tsx | 38 ++++++++++++------- server/index.js | 1 + 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/atproto-notifications/src/components/setup/Chrome.tsx b/atproto-notifications/src/components/setup/Chrome.tsx index dd625a3..47a37ff 100644 --- a/atproto-notifications/src/components/setup/Chrome.tsx +++ b/atproto-notifications/src/components/setup/Chrome.tsx @@ -1,6 +1,6 @@ import { Handle } from '../User'; -export function Chrome({ user, children }) { +export function Chrome({ user, onLogout, children }) { const content = children; const logout = () => null; return ( @@ -13,8 +13,7 @@ export function Chrome({ user, children }) { - {/* TODO: clear *all* info on logout */} - +

)} diff --git a/atproto-notifications/src/components/setup/WithServerHello.tsx b/atproto-notifications/src/components/setup/WithServerHello.tsx index af44f91..12afb0f 100644 --- a/atproto-notifications/src/components/setup/WithServerHello.tsx +++ b/atproto-notifications/src/components/setup/WithServerHello.tsx @@ -5,18 +5,9 @@ import { SecretPassword } from '../SecretPassword'; import { GetJson, PostJson } from '../Fetch'; import { Chrome } from './Chrome'; - - // const logout = useCallback(async () => { - // setRole('anonymous'); - // setUser(null); - // // TODO: clear indexeddb - // await fetch(`${host}/logout`, { - // method: 'POST', - // credentials: 'include', - // }); - // }); - export function WithServerHello({ children }) { + const [loggingOut, setLoggingOut] = useState(null); + const [helloKey, setHelloKey] = useState(0); const [whoamiKey, setWhoamiKey] = useState(0); const [whoamiInfo, setWhoamiInfo] = useState(null); @@ -32,9 +23,30 @@ export function WithServerHello({ children }) { setWhoamiKey(n => n + 1); }); + const handleLogout = useCallback(async () => { + setLoggingOut(true); + try { + const host = import.meta.env.VITE_NOTIFICATIONS_HOST; + await fetch(`${host}/logout`, { + method: 'POST', + credentials: 'include', + }); + // TODO: cancel subscription, clear storage, etc + } catch (e) { + console.error('logout fail', e); + } + setLoggingOut(null); + setHelloKey(n => n + 1); + }); + + if (loggingOut !== null) { + return

Logging out…

; + } + return ( { @@ -57,7 +69,7 @@ export function WithServerHello({ children }) { data={{ token: whoamiInfo.token }} credentials ok={({ did, role, webPushPublicKey }) => ( - + {childrenFor(did, role)} @@ -67,7 +79,7 @@ export function WithServerHello({ children }) { ) } else { return ( - + {childrenFor(did, role)} diff --git a/server/index.js b/server/index.js index 150c4f1..67740a7 100755 --- a/server/index.js +++ b/server/index.js @@ -334,6 +334,7 @@ const handleLogout = async (db, req, res, appSecret) => { .end(JSON.stringify({ reason: 'failed to register subscription' })); } updateSubs(db); + clearAccountCookie(res); res.setHeader('Content-Type', 'application/json'); res.writeHead(201); res.end(JSON.stringify({ sup: 'bye' })); -- 2.51.2