diff options
Diffstat (limited to 'vnext')
-rw-r--r-- | vnext/src/App.js | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/vnext/src/App.js b/vnext/src/App.js index 5d0cc832..9a0634ff 100644 --- a/vnext/src/App.js +++ b/vnext/src/App.js @@ -36,10 +36,11 @@ export default function App() { /** * @type {import('./api').SecureUser} */ - const anonymous = { + const unknownUser = { uid: -1 }; - const [visitor, setVisitor] = useState(anonymous); + + const [visitor, setVisitor] = useState(unknownUser); let updateStatus = () => { // refresh server visitor state (unread counters) @@ -53,8 +54,12 @@ export default function App() { useEffect(() => { let es; + const anonymousUser = { + uid: 0 + }; if (hash) { - me().then(visitor => auth(visitor)); + me().then(visitor => auth(visitor)) + .catch(() => setVisitor(anonymousUser)); if ('EventSource' in window) { const eventParams = { hash: hash }; let url = new URL(`https://juick.com/api/events?${qs.stringify(eventParams)}`); @@ -70,6 +75,8 @@ export default function App() { es.addEventListener('msg', updateStatus); setEventSource(es); } + } else { + setVisitor(anonymousUser); } return (() => { if (es && es.removeEventListener) { |