From c6562a43a64e35640e538e81e08aa88d5bad58d0 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Tue, 12 Mar 2024 16:01:24 -0400 Subject: [PATCH] fix: conditionally add the api key header --- src/store/actions/app.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/store/actions/app.js b/src/store/actions/app.js index 0a5741e1..2a421334 100644 --- a/src/store/actions/app.js +++ b/src/store/actions/app.js @@ -167,14 +167,19 @@ export const signInFromLocalStorage = () => { const serverAddress = localStorage.getItem('cadtRemoteServerAddress'); if (serverAddress) { + // Construct headers conditionally based on apiKey existence + const headers = { + 'Content-Type': 'application/json', + }; + if (apiKey) { + headers['x-api-key'] = apiKey; + } + // Ping the server to check if it's reachable and returns a 200 status. try { const response = await fetch(`${serverAddress}/v1/organizations`, { method: 'HEAD', - headers: { - 'Content-Type': 'application/json', - 'x-api-key': apiKey, - }, + headers: headers, }); if (response.status !== 200) { console.error(`Server returned status: ${response.status}`);