« get me outta code hell

scratchrlol - Simple HTML-based Scratch client
summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-xindex.js19
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')
   }