diff --git a/src/modules/integrations/event-streaming/EventStreamingTab.tsx b/src/modules/integrations/event-streaming/EventStreamingTab.tsx index 939f9809..98febf01 100644 --- a/src/modules/integrations/event-streaming/EventStreamingTab.tsx +++ b/src/modules/integrations/event-streaming/EventStreamingTab.tsx @@ -31,7 +31,10 @@ export default function EventStreamingTab() { Learn more about{" "} - + Event Streaming diff --git a/src/utils/api.tsx b/src/utils/api.tsx index 0fe61d53..2ba07a0d 100644 --- a/src/utils/api.tsx +++ b/src/utils/api.tsx @@ -1,4 +1,8 @@ -import { useOidc, useOidcFetch } from "@axa-fr/react-oidc"; +import { + useOidc, + useOidcAccessToken, + useOidcIdToken, +} from "@axa-fr/react-oidc"; import loadConfig from "@utils/config"; import { usePathname } from "next/navigation"; import useSWR from "swr"; @@ -32,8 +36,32 @@ async function apiRequest( return (await res.json()) as T; } +export function useNetBirdFetch() { + const tokenSource = config.tokenSource || "accessToken"; + const { idToken } = useOidcIdToken(); + const { accessToken } = useOidcAccessToken(); + + const nativeFetch = async (input: RequestInfo, init?: RequestInit) => { + const token = + tokenSource.toLowerCase() == "idtoken" ? idToken : accessToken; + const headers = { + "Content-Type": "application/json", + Accept: "application/json", + Authorization: `Bearer ${token}`, + }; + return fetch(input, { + ...init, + headers, + }); + }; + + return { + fetch: nativeFetch, + }; +} + export default function useFetchApi(url: string) { - const { fetch } = useOidcFetch(); + const { fetch } = useNetBirdFetch(); const handleErrors = useApiErrorHandling(); const { data, error, isLoading, isValidating, mutate } = useSWR( @@ -58,7 +86,7 @@ export default function useFetchApi(url: string) { } export function useApiCall(url: string) { - const { fetch } = useOidcFetch(); + const { fetch } = useNetBirdFetch(); const handleErrors = useApiErrorHandling(); return {