Cribbed some code from an example app as a guide, and the example app works as expected. In the below getProjects is from the example, and getAPIKey is mine. getProjects does resolve the promise successfully, but getAPIKey does not.
const getProjects = async () => {
const result = await asApp()
.requestJira(route`/rest/api/3/project/search`
);
return await result.json().then(data => {
return data;
})
};
const getAPIKey = async () => {
var result = await storage.getSecret("hubspotAPIKey")
return result
};
export const AdminConfigPage = () => {
const [projects, setProjects] = useAction(
() => getProjects(),
() => getProjects(),
);
const APIKey = getAPIKey();
Value is used as a default value for a form
<AdminPage>
<Form submitButtonText={"Set API key"} onsubmit={onProjectFormSubmit}>
<TextField label="Hubspot API Key" name="hubspotAPIKey" isRequired={true} defaultValue={APIKey}/>
</Form>
At this point, we’ve tried several permutations of this code, and all result in the same result; either a Promise object is returned rather than the expected string, or we get an undefined value.
We’ve moved the storage call to a separate file and after importing that function, same deal.
import { storage } from "@forge/api";
export const getFromStorageAPI = async (key, defaultvalue = "") => {
let foundData = await storage.get(key);
if (foundData === undefined) {
await storage.set(key, defaultvalue);
foundData = await storage.get(key);
}
return foundData;
};
But even calling this method where a value is set if not found, the response is undefined. What are we missing?