change apikey validation

This commit is contained in:
PhilReact 2025-02-20 18:50:21 +02:00
parent df87ca4d92
commit fe04bd5b97

View File

@ -197,18 +197,13 @@ export const NotAuthenticated = ({
url: key?.url, url: key?.url,
apikey: key?.apikey, apikey: key?.apikey,
}); });
const url = `${key?.url}/admin/apikey/test`; const url = `${key?.url}/lists/testlist?apiKey=${key?.apikey}`;
const response = await fetch(url, { const response = await fetch(url);
method: "GET",
headers: {
accept: "text/plain",
"X-API-KEY": key?.apikey, // Include the API key here
},
});
// Assuming the response is in plain text and will be 'true' or 'false' // Assuming the response is in plain text and will be 'true' or 'false'
const data = await response.text(); const data = await response.json();
if (data === "true") {
if (data && !data?.error) {
setIsValidApiKey(true); setIsValidApiKey(true);
setUseLocalNode(true); setUseLocalNode(true);
return return
@ -240,18 +235,13 @@ export const NotAuthenticated = ({
} else if (currentNodeRef.current) { } else if (currentNodeRef.current) {
payload = currentNodeRef.current; payload = currentNodeRef.current;
} }
const url = `${payload?.url}/admin/apikey/test`; const url = `${payload?.url}/lists/testlist?apiKey=${payload?.apikey}`;
const response = await fetch(url, { const response = await fetch(url);
method: "GET",
headers: {
accept: "text/plain",
"X-API-KEY": payload?.apikey, // Include the API key here
},
});
// Assuming the response is in plain text and will be 'true' or 'false' // Assuming the response is in plain text and will be 'true' or 'false'
const data = await response.text(); const data = await response.json();
if (data === "true") {
if (data && !data?.error) {
window window
.sendMessage("setApiKey", payload) .sendMessage("setApiKey", payload)
.then((response) => { .then((response) => {