0

我需要该函数getAUTH返回一个值,我稍后将分配给变量“AUTH”,但它返回 Promise {pending}。这是我的代码:

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

尝试像这样解决承诺: const AUTH = getAUTH().then(res => res) 但是分配值 AUTH 仍然没有返回值。在函数外部声明的变量可以从 Promise 中赋值吗?

我会很感激这方面的任何帮助。

4

0 回答 0