From fa1159da5332c288de74cb550e25ac05fb9c0940 Mon Sep 17 00:00:00 2001 From: Anwarul Islam Date: Wed, 29 Jan 2025 14:02:57 +0600 Subject: [PATCH] fix authorization hierarchy in postman import (#4686) Co-authored-by: nivedin --- .../src/helpers/import-export/import/postman.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/postman.ts b/packages/hoppscotch-common/src/helpers/import-export/import/postman.ts index 9e40f542..e43697e8 100644 --- a/packages/hoppscotch-common/src/helpers/import-export/import/postman.ts +++ b/packages/hoppscotch-common/src/helpers/import-export/import/postman.ts @@ -197,12 +197,17 @@ type PMRequestAuthDef< const getVariableValue = (defs: VariableDefinition[], key: string) => defs.find((param) => param.key === key)?.value as string | undefined -const getHoppReqAuth = (hoppAuth: Item["request"]["auth"]): HoppRESTAuth => { - if (!hoppAuth) return { authType: "none", authActive: true } +const getHoppReqAuth = ( + hoppAuth: Item["request"]["auth"] | null +): HoppRESTAuth => { + if (!hoppAuth) return { authType: "inherit", authActive: false } - // Cast to the type for more stricter checking down the line const auth = hoppAuth as unknown as PMRequestAuthDef + if (auth.type === "noauth") { + return { authType: "none", authActive: true } + } + if (auth.type === "basic") { return { authType: "basic", @@ -269,7 +274,7 @@ const getHoppReqAuth = (hoppAuth: Item["request"]["auth"]): HoppRESTAuth => { } } - return { authType: "none", authActive: true } + return { authType: "inherit", authActive: true } } const getHoppReqBody = ({ @@ -413,7 +418,7 @@ const getHoppFolder = (ig: ItemGroup): HoppCollection => A.map(getHoppFolder) ), requests: pipe(ig.items.all(), A.filter(isPMItem), A.map(getHoppRequest)), - auth: { authType: "inherit", authActive: true }, + auth: getHoppReqAuth(ig.auth), headers: [], })