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:
16
src/index.js
16
src/index.js
@@ -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) => {
|
||||
|
||||
if (status === 401) {
|
||||
Login()
|
||||
} else {
|
||||
await this.Socket.init()
|
||||
|
||||
if(status !== 401) {
|
||||
await this.onNavigate()
|
||||
Home()
|
||||
} else {
|
||||
Login()
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user