fix(airtrail): a new host does not inherit the stored API key

Saving the AirTrail settings with a different URL and the key field left
masked or blank kept the stored key, so the next sync sent the old
instance's key to the new host. The key now goes with the host, as it
already did for the connection test and for Dawarich: a new origin without
a new key clears it, a path edit on the same origin keeps it. The key is
cleared before the new address is written.
This commit is contained in:
Maurice
2026-11-12 16:58:24 +01:00
parent 56b9bac031
commit 74d243d8e0
3 changed files with 48 additions and 1 deletions
@@ -119,6 +119,17 @@ export class AirtrailService {
const provided = (apiKey || '').trim();
const newKey = provided && provided !== KEY_MASK ? maybe_encrypt_api_key(provided) : undefined;
// A key belongs to the instance it was issued on, as in testConnection. A
// new host with the key field left masked or blank would otherwise send the
// old instance's key to the new one on the next sync, so the key goes with
// the host. A path edit on the same origin keeps it. The key is cleared
// before the new address is written, so no moment stores the new address
// beside the old key.
if (newKey === undefined) {
const previousUrl = (await this.readRow(userId))?.airtrail_url ?? null;
if (movedHost(previousUrl, trimmedUrl)) await this.airtrailRepo.clearAirtrailApiKey(userId);
}
if (newKey !== undefined) {
await this.airtrailRepo.setAirtrailSettingsWithKey(
userId,