Skip to content

Commit

Permalink
Merge pull request #50 from Chia-Network/fix/apikey
Browse files Browse the repository at this point in the history
fix: conditionally add the api key header
  • Loading branch information
TheLastCicada authored Mar 12, 2024
2 parents 565391b + c6562a4 commit a7b0dfe
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/store/actions/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down

0 comments on commit a7b0dfe

Please sign in to comment.