diff --git a/src/index.js b/src/index.js index 873d9f8..add282c 100644 --- a/src/index.js +++ b/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) => { - - await this.Socket.init() - - if(status !== 401) { + if (status === 401) { + Login() + } else { + await this.Socket.init() await this.onNavigate() Home() - } else { - Login() } - }) + }); } }