WS connection crash fix

- constructor() in index.js would attempt to fetch profile with getProfile() before websocket connection was established
This commit is contained in:
2026-02-01 23:07:52 -05:00
parent 6262ce53aa
commit a68f35faf5

View File

@@ -118,20 +118,22 @@ let Global = class {
method: "GET",
credentials: "include",
headers: {
"Content-Type": "application/json"
"Accept": "application/json"
}
});
if(res.status === 401) {
return res.status
}
if (!res.ok) throw new Error("Failed to fetch profile");
if (!res.ok) return res.status;
const profile = await res.json();
console.log("getProfile: ", profile);
this.profile = profile
return 200;
} catch (err) {
console.error(err);
return 401;
}
}
@@ -139,16 +141,14 @@ let Global = class {
window.addEventListener("navigate", this.onNavigate)
this.getProfile().then(async (status) => {
await this.Socket.init()
if(status !== 401) {
if (status === 401) {
Login()
} else {
await this.Socket.init()
await this.onNavigate()
Home()
} else {
Login()
}
})
});
}
}