I've been working on a Typescript function that is supposed to generate and return a token value. Everything seems to be functioning properly, but I'm encountering an issue where the token value is only being logged to the console instead of being returned by the function.
createToken(): string{
axios.post(BASE_URL, body, { headers })
.then(async (response) => {
let responseData = response.data;
let getToken = JSON.stringify(responseData);
const obj = JSON.parse(getToken);
//The token value is currently being logged in the console, but how can it be properly returned from this function?
console.log(obj.access_token);
})
.catch(err => {
console.log(err);
});
return 'The desired token should be returned here';
}