From 89a6005e3cf0e1b50cbd953b0884f63ed629a37d Mon Sep 17 00:00:00 2001 From: Florrie Date: Mon, 19 Nov 2018 22:54:45 -0400 Subject: Fix error when viewing homepage while logged out --- index.js | 19 +++++++++++++------ 1 file 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`

Scratch Unofficial HTML Client

-

What's Happening?

- +

Welcome!

+ ${activityText ? fixWS` +

What's Happening?

+ + ` : ''} `, 'Scratch Homepage') } -- cgit 1.3.0-6-gf8a5