From d68fb596f19c33293595cd5f6d7327c469974fdd Mon Sep 17 00:00:00 2001 From: Ragavendaran Puliyadi Date: Fri, 17 Jan 2025 16:11:04 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20log=20error=20messages=20?= =?UTF-8?q?when=20OAuth=20fails.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/server/routes/oauth.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/api/server/routes/oauth.js b/api/server/routes/oauth.js index f84724841eb..dd4370afe6a 100644 --- a/api/server/routes/oauth.js +++ b/api/server/routes/oauth.js @@ -28,6 +28,12 @@ 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 +48,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 +68,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 +87,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 +105,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 +123,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'],