Skip to content

Commit 7515afa

Browse files
localai-botlocalai-bot
authored andcommitted
fix(settings): prevent API key duplication on save
- Convert api_keys_text (textarea input) to api_keys array before saving - Split text by newlines and trim each key to avoid duplicates - Set api_keys to empty array when no keys are provided - This fixes the issue where saving settings would duplicate API keys because the backend expects an array, not a text string Signed-off-by: localai-bot <localai-bot@localai.io>
1 parent 03a151a commit 7515afa

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

core/http/react-ui/src/pages/Settings.jsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,17 @@ export default function Settings() {
5555
const handleSave = async () => {
5656
setSaving(true)
5757
try {
58-
await settingsApi.save(settings)
58+
// Prepare settings for saving: convert api_keys_text to api_keys array
59+
const settingsToSave = { ...settings }
60+
if (settingsToSave.api_keys_text !== undefined && settingsToSave.api_keys_text !== null) {
61+
const text = settingsToSave.api_keys_text
62+
if (typeof text === 'string' && text.trim() !== '') {
63+
settingsToSave.api_keys = text.split('\n').map(k => k.trim()).filter(k => k !== '')
64+
} else {
65+
settingsToSave.api_keys = []
66+
}
67+
}
68+
await settingsApi.save(settingsToSave)
5969
addToast('Settings saved successfully', 'success')
6070
} catch (err) {
6171
addToast(`Save failed: ${err.message}`, 'error')

0 commit comments

Comments
 (0)