I am trying to automatically update a bearer key which is found in login.js and have it be used to in a new axios instance in customer.js.
I am struggling to find a way to implement the function from the login.js and use it within customer.js before a new instance is created.
Login.js
async function Login(){
const Bearerget = await axios.post("https://login.salesforce.com/services/oauth2/token", config.data)
const Bearer = `Bearer ${Bearerget.data.access_token}`
console.log(Bearer)
return `${Bearer}`
}
Customer.js
const login = require("./login");
Bearer = await login.Login()
const SalesforceClient = axios.create( {
baseURL: `url`,
timeout: 100000,
headers: {
'Content-Type': 'application/json',
'Authorization': Bearer
}
});
async function Customers(){
//Code
};
Customers()
What I get from the output is:
How do I run login.js, get the bearer key from the function, and then have it be updated in the axios instance in customer.js?