Asynchronous function returns Promise{pending} instead of a value

62 views Asked by At

I need the function getAUTH to return a value that i'll later assign to variable 'AUTH' but it returns Promise {pending}. This is my code:

const axios = require('axios')
const { getinfobipAuth } = require('../secrets-manager')

//get infobipAUTH from secret manager
const getAUTH = async () => await getinfobipAuth()
const AUTH = getAUTH()
console.log(AUTH)

axios.defaults.headers.common['Authorization'] = AUTH

Tried resolving the promise like: const AUTH = getAUTH().then(res => res) But assigning the value AUTH still doesn't return a value. Can a variable declared outside a function be assigned a value from a promise?

I'll appreciate any help with this.

0

There are 0 answers