diff --git a/packages/builder/src/components/settings/tabs/APIKeys.svelte b/packages/builder/src/components/settings/tabs/APIKeys.svelte index db07755d56..4545cf9b85 100644 --- a/packages/builder/src/components/settings/tabs/APIKeys.svelte +++ b/packages/builder/src/components/settings/tabs/APIKeys.svelte @@ -6,11 +6,10 @@ let keys = { budibase: "", sendGrid: "" } - async function updateKey(e) { - console.log("Event Key: ", e.detail) - // Send to endpoint when it exists - const response = await api.put(`/api/${$store.appId}`, data) - // const res = await response.json() + async function updateKey([key, value]) { + const response = await api.put(`/api/keys/${key}`, { value }) + const res = await response.json() + keys = { ...keys, ...res } } // Get Keys @@ -27,7 +26,7 @@
updateKey(['budibase', e.detail])} thin edit value={keys.budibase} @@ -35,7 +34,7 @@
updateKey(['sendgrid', e.detail])} thin edit value={keys.sendgrid} diff --git a/packages/server/src/api/controllers/apikeys.js b/packages/server/src/api/controllers/apikeys.js index 11dd0ac787..88758cb4c3 100644 --- a/packages/server/src/api/controllers/apikeys.js +++ b/packages/server/src/api/controllers/apikeys.js @@ -18,15 +18,10 @@ exports.fetch = async function (ctx) { } exports.update = async function (ctx) { + // Do something with ctx.request.body: <{ value: value }> ctx.status = 200 - ctx.message = `Updated ${ctx.params.key} succesfully.` - ctx.body = { - [ctx.params.key]: "somethingsomethingsomething" - } - - ctx.status = 200 - ctx.message = `User ${ctx.request.body.username} updated successfully.` - ctx.body = response + ctx.message = `Updated ${ctx.params.key} API key succesfully.` + ctx.body = { [ctx.params.key]: ctx.request.body.value } } const checkAccessLevel = async (db, accessLevelId) => {