Browse Source

fix unauthorized json access

AykutSarac 2 years ago
parent
commit
ebe39c2210
2 changed files with 8 additions and 4 deletions
  1. 1 1
      src/containers/Editor/BottomBar.tsx
  2. 7 3
      src/store/useJson.tsx

+ 1 - 1
src/containers/Editor/BottomBar.tsx

@@ -119,7 +119,7 @@ export const BottomBar = () => {
           {hasChanges ? <AiOutlineCloudUpload /> : <AiOutlineCloudSync />}
           {hasChanges ? "Unsaved Changes" : "Saved"}
         </StyledBottomBarItem>
-        {query.json && (
+        {data && (
           <>
             <StyledBottomBarItem onClick={setPrivate}>
               {isPrivate ? <AiOutlineLock /> : <AiOutlineUnlock />}

+ 7 - 3
src/store/useJson.tsx

@@ -36,13 +36,17 @@ const useJson = create<JsonStates & JsonActions>()((set, get) => ({
   getJson: () => get().json,
   fetchJson: async jsonId => {
     if (jsonId) {
-      const { data } = await altogic.endpoint.get(`json/${jsonId}`);
+      const { data, errors } = await altogic.endpoint.get(`json/${jsonId}`);
 
-      if (data) {
+      if (!errors) {
         const decompressedData = decompressFromBase64(data.json);
         if (decompressedData) {
           useGraph.getState().setGraph(decompressedData);
-          return set({ data, json: decompressedData ?? undefined, loading: false });
+          return set({
+            data: data,
+            json: decompressedData ?? undefined,
+            loading: false,
+          });
         }
       }
     }