Skip to content

Commit

Permalink
fix: log error messages when OAuth fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alt committed Jan 17, 2025
1 parent e309c6a commit 8ed9cb4
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions api/server/routes/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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'],
Expand All @@ -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'],
Expand All @@ -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,
}),
Expand All @@ -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'],
Expand All @@ -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'],
Expand Down

0 comments on commit 8ed9cb4

Please sign in to comment.