Seen in browser main window:
504 Gateway Time-out
The server didn't respond in time.
I’m making the initial request to grant scopes from my front end react.js app. however the redirect uri is my backend Express.js API. The auth code to token exchange step is where this error is occuring.
Here is the route handler callback at this endpoint:
router.get('/authCode', async (req: Request, res: Response) => {
const tokenExchangeEndpoint = 'https://app.asana.com/-/oauth_token';
const tokenRequestBody: IAuthCodeRequest = {
grant_type: EGrantTypes.authCode,
client_id: process.env.ASANA_CLIENT_ID!,
client_secret: process.env.ASANA_CLIENT_SECRET!,
redirect_uri: process.env.ASANA_HTTPS_REDIRECT_URL!,
code: req.query.code as string,
};
console.log('----------------------');
console.log('tokenRequestBody', tokenRequestBody);
console.log('----------------------');
try {
const response = await fetch(tokenExchangeEndpoint, {
method: 'post',
mode: 'cors',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify(tokenRequestBody),
});
const tokenObject: ITokenResponseBody = await response.json();
const { access_token, refresh_token } = tokenObject;
const { id, name, email } = tokenObject.data;
console.log('----------------------');
console.log('tokenObject', tokenObject);
console.log('----------------------');
The 2nd console block never prints to terminal. Here’s what I do see:
[nodemon] starting `node compiled/server.js`
Express server listening on port 6500
----------------------
tokenRequestBody {
grant_type: 'authorization_code',
client_id: '1188removed',
client_secret: 'b2dremoved',
redirect_uri: 'https://asanarepeater.ngrok.io/authCode',
code: '1/111920removed'
}
----------------------
(node:29618) UnhandledPromiseRejectionWarning: Error: TypeError: Cannot read property 'id' of undefined
at /home/owner/cp/project/compiled/oauth/router.js:136:23
at step (/home/owner/cp/project/compiled/oauth/router.js:33:23)
at Object.next (/home/owner/cp/project/compiled/oauth/router.js:14:53)
at fulfilled (/home/owner/cp/project/compiled/oauth/router.js:5:58)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:29618) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:29618) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
The values look good to me, but this fetch request is timing out I think (since the console statements following it never print). Is there an error above?