When I try to get storage.getSecret value, the result is a Promise, how to get value saved?

Hello,

I built a form for user to enter an api Key (ClientId and ClientSecret). I receive data (a json object) in a
resolver, then I save value with storage.setSecret() function. But when I try to get value saved with storage.getSecret() function, the result is a Promise object.
I doesn’t know how to get data saved, I don’t understand why I have a Promise object as a result when I was expecting to find the json object that I saved.

Front:

Resolver

resolver2.define('saveApiKey', ({payload}) => {
  console.log("Object : ", payload.apiKeyValue);
  console.log("ClientId received: ", payload.apiKeyValue.ClientId);
  console.log("ClientSecret received: ", payload.apiKeyValue.ClientSecret);

  storage.setSecret('ApiKey', payload.apiKeyValue); //Save data

  console.log("Read data saved : ", storage.getSecret('ApiKey'));
  return true;
});

Result Log:

INFO    10:17:34.666  fef6cbfd-87ea-4b80-9bd1-97849ca9375f  Object :  {
  ClientId: 'HelloClientIdValue',
  ClientSecret: 'HelloClientSecretValue'
}
INFO    10:17:34.668  fef6cbfd-87ea-4b80-9bd1-97849ca9375f  ClientId received:  HelloClientIdValue
INFO    10:17:34.669  fef6cbfd-87ea-4b80-9bd1-97849ca9375f  ClientSecret received:  HelloClientSecretValue
INFO    10:17:34.843  fef6cbfd-87ea-4b80-9bd1-97849ca9375f  Read data saved :  Promise {
  <pending>,
  [Symbol(async_id_symbol)]: 32,
  [Symbol(trigger_async_id_symbol)]: 9,
  [Symbol(kResourceStore)]: {
    container: {
      region: undefined,
      runtime: undefined,
      handler: 'handlerGlobalSettings'
    },
    proxy: {
[...]
    externalAuth: undefined,
    metrics: A {
      name: '',
      additionalInfo: [Object],
      _timers: [Array],
      _counters: Map(0) {},
      _gauges: Map(0) {},
      _children: Map(0) {}
    },
    featureFlags: [Function: featureFlags]
  }
}

Thank you for your help

Hi @ThibautFAURE
Just add await:

...
const secret = await storage.getSecret('ApiKey');
console.log("Read data saved : ", secret);
...
1 Like

Thank you very much :slight_smile: