From 447a339b319ff3cc86d513f73e4fd7d1064af39b Mon Sep 17 00:00:00 2001 From: sajjad Date: Sat, 25 Nov 2023 12:48:55 +0330 Subject: [PATCH] fix(frontend): handle backend status and fallback to demo version Ensure correct storage of backend status and handle the scenario where the backend is not available by falling back to the demo version of the app. --- frontend/middleware/setup.global.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/middleware/setup.global.ts b/frontend/middleware/setup.global.ts index 6618c59..67f97bf 100644 --- a/frontend/middleware/setup.global.ts +++ b/frontend/middleware/setup.global.ts @@ -15,14 +15,14 @@ async function checkBackendStatus() { }) .then((res) => res.json()) .then((data) => { - // stora status of backend - store.$patch({ isBackendReady: data.status === 200 }); + if (data.status === 200 || data.status === 503) + // stora status of backend + store.$patch({ isBackendReady: data.ok }); // if backend is not up and running then use demo version of app if (!store.isBackendReady) { const tokenInLocalStorage = - String(localStorage.getItem("loggedIn")) || - String(sessionStorage.getItem("loggedIn")) || - null; + JSON.parse(localStorage.getItem("loggedIn") as any) || + JSON.parse(sessionStorage.getItem("loggedIn") as any); store.$patch({ token: tokenInLocalStorage as any }); } })