From 8ed9cb42c3b59262f900955470e0900a40650e70 Mon Sep 17 00:00:00 2001 From: Alt Date: Fri, 17 Jan 2025 15:20:11 +0530 Subject: [PATCH] fix: log error messages when OAuth fails. --- api/server/routes/oauth.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/api/server/routes/oauth.js b/api/server/routes/oauth.js index f84724841eb..e2e15af9a6b 100644 --- a/api/server/routes/oauth.js +++ b/api/server/routes/oauth.js @@ -28,6 +28,18 @@ const oauthHandler = async (req, res) => { } }; +router.get( + '/error', + (req, res) => { + // A single error message is pushed by passport when authentication fails. + logger.error( + 'Error in OAuth authentication:', + { message: req.session.messages.pop() } + ); + res.redirect(`${domains.client}/login`); + }, +); + /** * Google Routes */ @@ -42,7 +54,7 @@ router.get( router.get( '/google/callback', passport.authenticate('google', { - failureRedirect: `${domains.client}/login`, + failureRedirect: `${domains.client}/oauth/error`, failureMessage: true, session: false, scope: ['openid', 'profile', 'email'], @@ -62,7 +74,7 @@ router.get( router.get( '/facebook/callback', passport.authenticate('facebook', { - failureRedirect: `${domains.client}/login`, + failureRedirect: `${domains.client}/oauth/error`, failureMessage: true, session: false, scope: ['public_profile'], @@ -81,7 +93,7 @@ router.get( router.get( '/openid/callback', passport.authenticate('openid', { - failureRedirect: `${domains.client}/login`, + failureRedirect: `${domains.client}/oauth/error`, failureMessage: true, session: false, }), @@ -99,7 +111,7 @@ router.get( router.get( '/github/callback', passport.authenticate('github', { - failureRedirect: `${domains.client}/login`, + failureRedirect: `${domains.client}/oauth/error`, failureMessage: true, session: false, scope: ['user:email', 'read:user'], @@ -117,7 +129,7 @@ router.get( router.get( '/discord/callback', passport.authenticate('discord', { - failureRedirect: `${domains.client}/login`, + failureRedirect: `${domains.client}/oauth/error`, failureMessage: true, session: false, scope: ['identify', 'email'],