mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-23 23:18:12 +02:00
fix(settings): prevent empty string API keys from being saved or preserved
- Add .min(1) validation to insertOpenrouterConfigSchema - Strip empty/whitespace-only apiKey before fallback to existing key - Return 400 if resulting apiKey is empty (forces user to enter valid key)
This commit is contained in:
1 parent
b7ef4940f7
commit
35cf21209f
2 files changed
+9
-2
No files matched your search
+7
-2
@@ -1898,12 +1898,17 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Si apiKey n'est pas fourni, garder l'ancien
|
// Si apiKey n'est pas fourni ou vide, garder l'ancien
|
||||||
|
const incomingKey = updateData.apiKey?.trim() || undefined;
|
||||||
const finalData = {
|
const finalData = {
|
||||||
...updateData,
|
...updateData,
|
||||||
apiKey: updateData.apiKey || existingConfig.apiKey,
|
apiKey: incomingKey || existingConfig.apiKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!finalData.apiKey) {
|
||||||
|
return res.status(400).json({ error: "Clé API OpenRouter manquante. Veuillez entrer une clé API valide." });
|
||||||
|
}
|
||||||
|
|
||||||
config = await storage.updateOpenrouterConfig(userId, finalData);
|
config = await storage.updateOpenrouterConfig(userId, finalData);
|
||||||
} else {
|
} else {
|
||||||
// Pour les créations, exiger tous les champs
|
// Pour les créations, exiger tous les champs
|
||||||
|
|||||||
@@ -410,6 +410,8 @@ export const insertOpenrouterConfigSchema = createInsertSchema(openrouterConfig)
|
|||||||
id: true,
|
id: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
updatedAt: true,
|
updatedAt: true,
|
||||||
|
}).extend({
|
||||||
|
apiKey: z.string().min(1, "La clé API ne peut pas être vide"),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const updateOpenrouterConfigSchema = insertOpenrouterConfigSchema.partial({
|
export const updateOpenrouterConfigSchema = insertOpenrouterConfigSchema.partial({
|
||||||
|
|||||||
Reference in new issue
Block a user