From be006fcc7c6113ad36245933a025ad5a181a0c15 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 15 Sep 2024 19:22:03 +0530 Subject: [PATCH] fix: ts errors --- server/src/routes/auth.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index f240bdf0..cdb2980c 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -25,17 +25,21 @@ router.get('/auth/google', (req, res) => { // Callback route for Google OAuth 2.0 router.get('/auth/google/callback', async (req, res) => { - const { code } = req.query; - try { - const { tokens } = await oauth2Client.getToken(code); - oauth2Client.setCredentials(tokens); - // Store tokens securely (e.g., in a database) - res.send('Authentication successful'); - } catch (error) { - console.error('Error during authentication:', error); - res.status(500).send('Authentication failed'); + const code = req.query.code; + if (typeof code !== 'string') { + res.status(400).send('Invalid authorization code'); + return; } -}); + try { + const { tokens } = await oauth2Client.getToken(code); + oauth2Client.setCredentials(tokens); + // Store tokens securely (e.g., in a database) + res.send('Authentication successful'); + } catch (error) { + console.error('Error during authentication:', error); + res.status(500).send('Authentication failed'); + } + }); router.get('/sheets', async (req, res) => { try {