0

getSecretAsync() is an async method therefore I cannot use await in my config export as it'll be top level. So I created a function to get the secret, however the assigned global variable does not retain its' value, see below.

Could you let me know what I'm doing wrong?

import { newclass } from '../newclass';

var globalVar ="";

const getAsync = async () => {
    const key = await newclass.getSecretAsync("the-secret")
    return key;
  };

  getAsync().then(e=>{
      globalVar = e;
      console.log(globalVar + '****'); // globalVar returns the key 
    });
 
     console.log(globalVar + '**'); // globalVar is empty
 
export const credentials = 
{
    key:globalVar, //globalVar is empty
    region: 'eu', 
    user: 'isi'
};
marwaha.ks
  • 540
  • 1
  • 7
  • 19

0 Answers0