From 5a040215e155693386fdaa5e237a5598a346e0d8 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 14 Aug 2019 11:45:13 +0300 Subject: Fix anonymous user flow and broken hash flow --- vnext/src/App.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'vnext/src') 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) { -- cgit v1.2.3