feat: kick out users who arent signed in

This commit is contained in:
kittentm 2026-03-21 03:42:36 +01:00
commit 50a36e2db4
No known key found for this signature in database
GPG key ID: AC43DFDBC1F44A91
4 changed files with 41 additions and 12 deletions

View file

@ -144,8 +144,6 @@ window.loadHeader(async function(headerContainer) {
const udemaeKey = equipped.Udemae !== undefined ? String(equipped.Udemae) : String(finalData.Udemae || ""); const udemaeKey = equipped.Udemae !== undefined ? String(equipped.Udemae) : String(finalData.Udemae || "");
const rankGrade = udemaeMap[udemaeKey] || (udemaeKey !== "undefined" && udemaeKey !== "" ? udemaeKey : "--"); 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 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"'; const fallback = className.includes('weapon') || className.includes('gear') ? 'this.src="/assets/weapons/NotFound^w.png"' : 'this.src="../assets/ability/ParameterIcon^q.png"';
return src ? `<img class="${className}" src="${src}" onerror='${fallback}' />` : ''; return src ? `<img class="${className}" src="${src}" onerror='${fallback}' />` : '';
@ -241,15 +239,24 @@ window.loadHeader(async function(headerContainer) {
} }
try { 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([ const [profileRes, equipRes, historyRes] = await Promise.all([
fetch("/api/v1/me", { credentials: 'include' }).then(res => res.ok ? res.json() : {}), handleFetch("/api/v1/me"),
fetch("/api/v1/me/equipment", { credentials: 'include' }).then(res => res.ok ? res.json() : {}), handleFetch("/api/v1/me/equipment"),
fetch("/api/v1/me/equipment/history", { credentials: 'include' }).then(res => res.ok ? res.json() : []) handleFetch("/api/v1/me/equipment/history")
]); ]);
await renderData(profileRes, false); await renderData(profileRes, false);
await renderData(equipRes, 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)); sessionStorage.setItem('user_cache', JSON.stringify(combinedData));
} catch (err) { } catch (err) {
if (cacheFound) { if (cacheFound) {

View file

@ -65,8 +65,15 @@ window.loadHeader(function(headerContainer) {
if (cached) renderData(JSON.parse(cached)); if (cached) renderData(JSON.parse(cached));
fetch("/api/v1/me", { credentials: 'include' }) 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 => { .then(data => {
if (!data) return;
sessionStorage.setItem('user_cache', JSON.stringify(data)); sessionStorage.setItem('user_cache', JSON.stringify(data));
renderData(data); renderData(data);
}) })

View file

@ -67,8 +67,15 @@ window.loadHeader(function(headerContainer) {
if (cached) renderData(JSON.parse(cached)); if (cached) renderData(JSON.parse(cached));
fetch("/api/v1/me", { credentials: 'include' }) 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 => { .then(data => {
if (!data) return;
sessionStorage.setItem('user_cache', JSON.stringify(data)); sessionStorage.setItem('user_cache', JSON.stringify(data));
renderData(data); renderData(data);
}) })

View file

@ -78,13 +78,21 @@ window.loadHeader(async function(headerContainer) {
} }
try { try {
const [profileRes, rotationsData] = await Promise.all([ const [profileRes] = await Promise.all([
fetch("/api/v1/me", { credentials: 'include' }).then(res => res.ok ? res.json() : {}), fetch("/api/v1/me", { credentials: 'include' }).then(res => {
if (res.redirected) {
window.location.href = res.url;
return {};
}
return res.ok ? res.json() : {};
}),
renderStages() renderStages()
]); ]);
await renderData(profileRes); if (profileRes && Object.keys(profileRes).length > 0) {
sessionStorage.setItem('user_cache', JSON.stringify(profileRes)); await renderData(profileRes);
sessionStorage.setItem('user_cache', JSON.stringify(profileRes));
}
} catch (err) { } catch (err) {
if (!cacheReady) { if (!cacheReady) {
const nameEl = document.getElementById('mii-name'); const nameEl = document.getElementById('mii-name');