I'm writing an app that needs to authenticate externally with a service. To do this, I'm using express
to listen to the redirect and get the data I need. However, I would like to return that data to the main scope. Here's what I have so far:
const authorize = () => {
app.get('/', (req, res) => {
res.status(200).send('<script>window.close()</script>')
return req.query.code;
});
app.listen(3000, () => {
console.log('listening');
});
}
const code = authorize();
req.query.code
is the data I need, and I would like to return it from authorize()
. Instead I get undefined
. What is the best practice to accomplish what I want?