Skip to content

Commit

Permalink
Merge branch 'master' into jacob/review-sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
js0mmer authored Jun 1, 2023
2 parents 4bd9889 + cedc558 commit 211a8de
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions api/src/controllers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ router.get('/auth/google',
passport.authenticate('google', {
scope: ['https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email'],
state: req.headers.host
})(req, res);
}
);
Expand All @@ -46,6 +47,16 @@ router.get('/auth/google',
*/
router.get('/auth/google/callback', function (req, res) {
const returnTo = req.session.returnTo;
let host: string = req.query.state as string;
// all staging auths will redirect their callback to prod since all callback URLs must be registered
// with google cloud for security reasons and it isn't feasible to register the callback URLs for all
// staging instances
// if we are not on a staging instance (on prod or local) but original host is a staging instance, redirect back to host
if (host.startsWith('staging-') && !req.headers.host?.startsWith('staging')) {
// req.url doesn't include /api/users part, only /auth/google/callback? and whatever params after that
res.redirect('https://' + host + '/api/users' + req.url);
return;
}
passport.authenticate('google', { failureRedirect: '/', session: true },
// provides user information to determine whether or not to authenticate
function (err, user, info) {
Expand Down

0 comments on commit 211a8de

Please sign in to comment.