From f19bc243c535dbc1f964ba02b6ec665bf126178e Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja <1805317@kiit.ac.in> Date: Wed, 24 Jan 2024 14:48:58 +0530 Subject: [PATCH] fix: comments addresssed --- src/hooks/AuthHooks.res | 45 +++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/src/hooks/AuthHooks.res b/src/hooks/AuthHooks.res index 8c1266d9d..29995a58a 100644 --- a/src/hooks/AuthHooks.res +++ b/src/hooks/AuthHooks.res @@ -10,44 +10,35 @@ type sessionStorage = { external dictToObj: Js.Dict.t<'a> => {..} = "%identity" @val external atob: string => string = "atob" +let headersForXFeature = (~uri, ~headers) => { + if uri->String.includes("lottie-files") || uri->String.includes("config/merchant-access") { + headers->Dict.set("Content-Type", `application/json`) + } else { + headers->Dict.set("x-feature", "hyperswitch-custom") + } +} + let getHeaders = (~uri, ~headers, ~xFeatureRoute, ()) => { let hyperSwitchToken = LocalStorage.getItem("login")->Js.Nullable.toOption let isMixpanel = uri->String.includes("mixpanel") - let headersForXFeature = (~token) => - if ( - uri->Js.String2.includes("lottie-files") || uri->Js.String2.includes("config/merchant-access") - ) { - headers->Dict.set("Content-Type", `application/json`) - headers->Dict.set("authorization", `Bearer ${token}`) - headers->Dict.set("api-key", `hyperswitch`) - headers - } else { - headers->Dict.set("authorization", `Bearer ${token}`) - headers->Dict.set("api-key", `hyperswitch`) - headers->Dict.set("x-feature", "hyperswitch-custom") - headers - } - let headerObj = if isMixpanel { [ ("Content-Type", "application/x-www-form-urlencoded"), ("accept", "application/json"), ]->Dict.fromArray } else { - let headersDict = switch hyperSwitchToken { - | Some(token) => - xFeatureRoute - ? headersForXFeature(~token) - : { - headers->Dict.set("authorization", `Bearer ${token}`) - headers->Dict.set("api-key", `hyperswitch`) - headers - } - - | None => xFeatureRoute ? headersForXFeature(~token="") : headers + if xFeatureRoute { + headersForXFeature(~headers, ~uri) + } + switch hyperSwitchToken { + | Some(token) => { + headers->Dict.set("authorization", `Bearer ${token}`) + headers->Dict.set("api-key", `hyperswitch`) + } + | None => () } - headersDict + headers } Fetch.HeadersInit.make(headerObj->dictToObj) }