diff --git a/server/routes.ts b/server/routes.ts index 7e3d172..16e32bd 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -1898,12 +1898,17 @@ export async function registerRoutes(app: Express): Promise { 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 = { ...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); } else { // Pour les créations, exiger tous les champs diff --git a/shared/schema.ts b/shared/schema.ts index 6b88bde..b2c4b43 100644 --- a/shared/schema.ts +++ b/shared/schema.ts @@ -410,6 +410,8 @@ export const insertOpenrouterConfigSchema = createInsertSchema(openrouterConfig) id: true, createdAt: true, updatedAt: true, +}).extend({ + apiKey: z.string().min(1, "La clé API ne peut pas être vide"), }); export const updateOpenrouterConfigSchema = insertOpenrouterConfigSchema.partial({