I have a function which is returning information from an API call,part of which is an access token. I then need to plug that access token into the parameters of a redirect URL. Only problem is that thw redirect is invoked before the data is returned. Any ideas on how I can wait till the data is returned before invoking the redirect?
Here's the code:
oauthClient.createToken(req.url)
.then((authResponse) => {
oauth2_token_json = JSON.stringify(authResponse.getJson(), null,2);
let newToken = JSON.parse(oauth2_token_json)
accessToken = newToken.access_token
})
.catch((e) => {
console.error(e);
});
res.redirect(`http://localhost:3000/?token=${accessToken}`)
});