|
|
|
@ -3,13 +3,21 @@ |
|
|
|
import { store } from "builderStore" |
|
|
|
import api from "builderStore/api" |
|
|
|
import posthog from "posthog-js" |
|
|
|
import analytics from "../../../analytics" |
|
|
|
|
|
|
|
let keys = { budibase: "", sendGrid: "" } |
|
|
|
|
|
|
|
async function updateKey([key, value]) { |
|
|
|
if (key === "budibase") { |
|
|
|
const isValid = await analytics.identifyByApiKey(value) |
|
|
|
if (!isValid) { |
|
|
|
// TODO: add validation message |
|
|
|
keys = { ...keys } |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
const response = await api.put(`/api/keys/${key}`, { value }) |
|
|
|
const res = await response.json() |
|
|
|
if (key === "budibase") posthog.identify(value) |
|
|
|
keys = { ...keys, ...res } |
|
|
|
} |
|
|
|
|
|
|
|
@ -17,6 +25,8 @@ |
|
|
|
async function fetchKeys() { |
|
|
|
const response = await api.get(`/api/keys/`) |
|
|
|
const res = await response.json() |
|
|
|
// dont want this to ever be editable, as its fetched based on Api Key |
|
|
|
if (res.userId) delete res.userId |
|
|
|
keys = res |
|
|
|
} |
|
|
|
|
|
|
|
|