diff options
author | Florrie <towerofnix@gmail.com> | 2018-11-19 22:54:45 -0400 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-11-19 22:54:45 -0400 |
commit | 89a6005e3cf0e1b50cbd953b0884f63ed629a37d (patch) | |
tree | 49080d6fac7bb4257c32816d93aa33d1b802f56e | |
parent | 2bcafc451ff8c930909ec8bf6ccef2dc706b627b (diff) |
Fix error when viewing homepage while logged out
-rwxr-xr-x | index.js | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/index.js b/index.js index 1619d6a..361803b 100755 --- a/index.js +++ b/index.js @@ -569,15 +569,22 @@ const handleRequest = async (request, response) => { } if (urlParts.length === 0) { - const activity = await fetch(`https://api.scratch.mit.edu/users/${cookie.username}/following/users/activity?limit=8&x-token=${cookie.token}`).then(res => res.json()) - const activityText = activity.map(templates.activity).join('\n') + let activityText = '' + + if (cookie.username) { + const activity = await fetch(`https://api.scratch.mit.edu/users/${cookie.username}/following/users/activity?limit=8&x-token=${cookie.token}`).then(res => res.json()) + activityText = activity.map(templates.activity).join('\n') + } return page(request, response, fixWS` <h1>Scratch Unofficial HTML Client</h1> - <h2>What's Happening?</h2> - <ul> - ${activityText} - </ul> + <p>Welcome!</p> + ${activityText ? fixWS` + <h2>What's Happening?</h2> + <ul> + ${activityText} + </ul> + ` : ''} `, 'Scratch Homepage') } |