diff --git a/app/api/admin/plugins/[id]/config/route.ts b/app/api/admin/plugins/[id]/config/route.ts index 7b2dfbf5..d17c494e 100644 --- a/app/api/admin/plugins/[id]/config/route.ts +++ b/app/api/admin/plugins/[id]/config/route.ts @@ -51,13 +51,18 @@ export async function GET( const config = await getPluginConfig(id); - let response: Record = config; - if (!isAdmin && plugin.configSchema) { + let response: Record; + if (isAdmin) { + response = config; + } else { response = {}; - for (const [key, value] of Object.entries(config)) { - const field = plugin.configSchema[key]; - if (field?.type === 'secret') continue; - response[key] = value; + const schema = plugin.configSchema; + if (schema) { + for (const [key, value] of Object.entries(config)) { + const field = schema[key]; + if (!field || field.type === 'secret') continue; + response[key] = value; + } } } @@ -110,6 +115,13 @@ export async function PUT( return NextResponse.json({ error: 'Invalid key format' }, { status: 400 }); } + if (plugin.configSchema && !plugin.configSchema[body.key]) { + return NextResponse.json( + { error: 'Key is not declared in the plugin configSchema' }, + { status: 400 }, + ); + } + await setPluginConfig(id, body.key, body.value); return NextResponse.json({ ok: true }); } catch {