aboutsummaryrefslogtreecommitdiff
path: root/vnext/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-08-14 11:45:13 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:55 +0300
commit5a040215e155693386fdaa5e237a5598a346e0d8 (patch)
tree3d8e633fb28cbc9bcc8df98faf7ca035366ffb5a /vnext/src
parent647a11daa6cb73cc3f903c31335f7ca3a9e59d8b (diff)
Fix anonymous user flow and broken hash flow
Diffstat (limited to 'vnext/src')
-rw-r--r--vnext/src/App.js13
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) {