check api key list

This commit is contained in:
Chris Bisset 2025-03-23 00:06:24 +00:00
parent 987cbdcda1
commit ac15a15caf
2 changed files with 10 additions and 2 deletions

View file

@ -49,6 +49,7 @@
export async function rotateAPIKey() {
for (const key of appSettings.apiKeyList) {
// select the current key being used in the app settings
if (persistentAppSettings.headscaleAPIKey.startsWith(key.prefix)) {
let currentKey = key;
@ -59,14 +60,18 @@
// create a new API key with the new expiration
let apiKey = await createNewAPIKey(newExpiration);
// The above should always return a value
// The above should always return a value, let's check that
if (apiKey == undefined) {
throw new Error('expecting API key string, string was undefined');
}
// Set the new key as the current key in the persistent settings
persistentAppSettings.headscaleAPIKey = apiKey;
// Expire the previously current key
await expireAPIKey(currentKey.prefix);
// Get keys again to make sure it all worked
await getAPIKeys();
}

View file

@ -9,7 +9,10 @@
function rotateAPIKeyClick() {
rotateButtonDisabled = true;
rotateAPIKey().then(() => {rotateButtonDisabled = false});
rotateAPIKey().then(() => {
rotateButtonDisabled = false;
console.log(appSettings.apiKeyList);
});
}
</script>