From b6f3b24b9e889f0db74cf62ed041ded580f99625 Mon Sep 17 00:00:00 2001 From: nivedin Date: Sat, 9 Dec 2023 14:10:16 +0530 Subject: [PATCH] fix: add auth and headers for old collection --- .../collections/collections.platform.ts | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/packages/hoppscotch-selfhost-web/src/platform/collections/collections.platform.ts b/packages/hoppscotch-selfhost-web/src/platform/collections/collections.platform.ts index dcb028c87..1b9de9351 100644 --- a/packages/hoppscotch-selfhost-web/src/platform/collections/collections.platform.ts +++ b/packages/hoppscotch-selfhost-web/src/platform/collections/collections.platform.ts @@ -106,8 +106,13 @@ function exportedCollectionToHoppCollection( ): HoppCollection { if (collectionType == "REST") { const restCollection = collection as ExportedUserCollectionREST - const data = restCollection.data ? JSON.parse(restCollection.data) : null - + const data = + restCollection.data && restCollection.data != "null" + ? JSON.parse(restCollection.data) + : { + auth: { authType: "inherit", authActive: false }, + headers: [], + } return { id: restCollection.id, v: 1, @@ -142,12 +147,18 @@ function exportedCollectionToHoppCollection( testScript, }) ), - auth: data.auth ?? { authType: "inherit", authActive: false }, - headers: data.headers ?? [], + auth: data.auth, + headers: data.headers, } } else { const gqlCollection = collection as ExportedUserCollectionGQL - const data = gqlCollection.data ? JSON.parse(gqlCollection.data) : null + const data = + gqlCollection.data && gqlCollection.data !== "null" + ? JSON.parse(gqlCollection.data) + : { + auth: { authType: "inherit", authActive: false }, + headers: [], + } return { id: gqlCollection.id, @@ -298,9 +309,15 @@ function setupUserCollectionCreatedSubscription() { }) } else { // root collections won't have parentCollectionID - const data = res.right.userCollectionCreated.data - ? JSON.parse(res.right.userCollectionCreated.data) - : null + const data = + res.right.userCollectionCreated.data && + res.right.userCollectionCreated.data != "null" + ? JSON.parse(res.right.userCollectionCreated.data) + : { + auth: { authType: "inherit", authActive: false }, + headers: [], + } + runDispatchWithOutSyncing(() => { collectionType == "GQL" ? addGraphqlCollection({ @@ -308,19 +325,16 @@ function setupUserCollectionCreatedSubscription() { folders: [], requests: [], v: 1, - auth: data?.auth ?? { authType: "inherit", authActive: false }, - headers: data?.headers ?? [], + auth: data.auth, + headers: data.headers, }) : addRESTCollection({ name: res.right.userCollectionCreated.title, folders: [], requests: [], v: 1, - auth: data?.auth ?? { - authType: "inherit", - authActive: false, - }, - headers: data?.headers ?? [], + auth: data.auth, + headers: data?.headers, }) const localIndex = collectionStore.value.state.length - 1