diff --git a/web-app/src/lib/completion.ts b/web-app/src/lib/completion.ts index f523881aa..1e8c08861 100644 --- a/web-app/src/lib/completion.ts +++ b/web-app/src/lib/completion.ts @@ -181,9 +181,11 @@ export const sendCompletion = async ( return encryptedKey } } - + if (!secretKey) { + throw new Error('Encryption key unavailable: cannot encrypt API key.') + } const apiKey = provider.api_key - ? decryptApiKey(provider.api_key, secretKey || 'fallback-key') + ? decryptApiKey(provider.api_key, secretKey) : (secretKey ?? '') const tokenJS = new TokenJS({ diff --git a/web-app/src/routes/settings/providers/$providerName.tsx b/web-app/src/routes/settings/providers/$providerName.tsx index 1785c3551..9d1e267c5 100644 --- a/web-app/src/routes/settings/providers/$providerName.tsx +++ b/web-app/src/routes/settings/providers/$providerName.tsx @@ -536,10 +536,11 @@ function ProviderDetail() { const secretKey = await getServiceHub() .core() .getAppToken() - updateObj.api_key = CryptoJS.AES.encrypt( - newValue, - secretKey || 'fallback-key' - ).toString() + if (secretKey) + updateObj.api_key = CryptoJS.AES.encrypt( + newValue, + secretKey + ).toString() } else if ( settingKey === 'base-url' && typeof newValue === 'string' @@ -555,7 +556,7 @@ function ProviderDetail() { ) if (deviceSettingIndex !== -1) { - ( + ;( newSettings[deviceSettingIndex] .controller_props as { value: string