I'm trying to write a function in Typescript that returns a token value. Everything works perfectly up until the point where the token value is simply logged into the console and not returned.
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);
//VALUE IS LOGGED IN THE CONSOLE, HOW CAN IT BE RETURNED??
console.log(obj.access_token);
})
.catch(err => {
console.log(err);
})
return 'TOKEN SHOULD BE RETURNED HERE';
}