From 50a36e2db4d6a4c68ddc1142726d5d4cf0765ebc Mon Sep 17 00:00:00 2001 From: KittenTM Date: Sat, 21 Mar 2026 03:42:36 +0100 Subject: [PATCH] feat: kick out users who arent signed in --- equipment/equipment.js | 19 +++++++++++++------ friend_list/friendlist.js | 9 ++++++++- ranking/rank.js | 9 ++++++++- stages/stages.js | 16 ++++++++++++---- 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/equipment/equipment.js b/equipment/equipment.js index 5002fe6..44f5dfe 100644 --- a/equipment/equipment.js +++ b/equipment/equipment.js @@ -144,8 +144,6 @@ window.loadHeader(async function(headerContainer) { const udemaeKey = equipped.Udemae !== undefined ? String(equipped.Udemae) : String(finalData.Udemae || ""); const rankGrade = udemaeMap[udemaeKey] || (udemaeKey !== "undefined" && udemaeKey !== "" ? udemaeKey : "--"); - // do this bs so splahoon will be happy - // im glad i can make people happy with a 2 liner though.. C: const renderImg = (src, className) => { const fallback = className.includes('weapon') || className.includes('gear') ? 'this.src="/assets/weapons/NotFound^w.png"' : 'this.src="../assets/ability/ParameterIcon^q.png"'; return src ? `` : ''; @@ -241,15 +239,24 @@ window.loadHeader(async function(headerContainer) { } try { + const handleFetch = async (url) => { + const res = await fetch(url, { credentials: 'include' }); + if (res.redirected) { + window.location.href = res.url; + return {}; + } + return res.ok ? res.json() : {}; + }; + const [profileRes, equipRes, historyRes] = await Promise.all([ - fetch("/api/v1/me", { credentials: 'include' }).then(res => res.ok ? res.json() : {}), - fetch("/api/v1/me/equipment", { credentials: 'include' }).then(res => res.ok ? res.json() : {}), - fetch("/api/v1/me/equipment/history", { credentials: 'include' }).then(res => res.ok ? res.json() : []) + handleFetch("/api/v1/me"), + handleFetch("/api/v1/me/equipment"), + handleFetch("/api/v1/me/equipment/history") ]); await renderData(profileRes, false); await renderData(equipRes, false); - await renderData({ history: historyRes }, false); + await renderData({ history: Array.isArray(historyRes) ? historyRes : [] }, false); sessionStorage.setItem('user_cache', JSON.stringify(combinedData)); } catch (err) { if (cacheFound) { diff --git a/friend_list/friendlist.js b/friend_list/friendlist.js index 7e9f3b2..3be28bd 100644 --- a/friend_list/friendlist.js +++ b/friend_list/friendlist.js @@ -65,8 +65,15 @@ window.loadHeader(function(headerContainer) { if (cached) renderData(JSON.parse(cached)); fetch("/api/v1/me", { credentials: 'include' }) - .then(res => res.ok ? res.json() : Promise.reject(res)) + .then(res => { + if (res.redirected) { + window.location.href = res.url; + return; + } + return res.ok ? res.json() : Promise.reject(res); + }) .then(data => { + if (!data) return; sessionStorage.setItem('user_cache', JSON.stringify(data)); renderData(data); }) diff --git a/ranking/rank.js b/ranking/rank.js index b034caf..7b4c61c 100644 --- a/ranking/rank.js +++ b/ranking/rank.js @@ -67,8 +67,15 @@ window.loadHeader(function(headerContainer) { if (cached) renderData(JSON.parse(cached)); fetch("/api/v1/me", { credentials: 'include' }) - .then(res => res.ok ? res.json() : Promise.reject(res)) + .then(res => { + if (res.redirected) { + window.location.href = res.url; + return; + } + return res.ok ? res.json() : Promise.reject(res); + }) .then(data => { + if (!data) return; sessionStorage.setItem('user_cache', JSON.stringify(data)); renderData(data); }) diff --git a/stages/stages.js b/stages/stages.js index 8cc7d8c..b646a46 100644 --- a/stages/stages.js +++ b/stages/stages.js @@ -78,13 +78,21 @@ window.loadHeader(async function(headerContainer) { } try { - const [profileRes, rotationsData] = await Promise.all([ - fetch("/api/v1/me", { credentials: 'include' }).then(res => res.ok ? res.json() : {}), + const [profileRes] = await Promise.all([ + fetch("/api/v1/me", { credentials: 'include' }).then(res => { + if (res.redirected) { + window.location.href = res.url; + return {}; + } + return res.ok ? res.json() : {}; + }), renderStages() ]); - await renderData(profileRes); - sessionStorage.setItem('user_cache', JSON.stringify(profileRes)); + if (profileRes && Object.keys(profileRes).length > 0) { + await renderData(profileRes); + sessionStorage.setItem('user_cache', JSON.stringify(profileRes)); + } } catch (err) { if (!cacheReady) { const nameEl = document.getElementById('mii-name');