feat: callback google auth

This commit is contained in:
karishmas6
2024-09-15 19:15:26 +05:30
parent 7f5a5839ec
commit 13ecfae2d6

View File

@@ -21,4 +21,18 @@ router.get('/auth/google', (req, res) => {
]
});
res.redirect(url);
});
});
// 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');
}
});