From 3f001dca2c8a4cffc6db28708c32c983908d691a Mon Sep 17 00:00:00 2001 From: PaulD987 <73899671+PaulD987@users.noreply.github.com> Date: Fri, 19 Mar 2021 01:56:59 +0000 Subject: [PATCH] fix: loginRedirect doesn't work for non local strategies (#3222) --- server/controllers/auth.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/server/controllers/auth.js b/server/controllers/auth.js index 037652d4..9d691087 100644 --- a/server/controllers/auth.js +++ b/server/controllers/auth.js @@ -71,7 +71,19 @@ router.all('/login/:strategy/callback', async (req, res, next) => { strategy: req.params.strategy }, { req, res }) res.cookie('jwt', authResult.jwt, { expires: moment().add(1, 'y').toDate() }) - res.redirect(authResult.redirect) + + const loginRedirect = req.cookies['loginRedirect'] + if (loginRedirect === '/' && authResult.redirect) { + res.clearCookie('loginRedirect') + res.redirect(authResult.redirect) + } else if (loginRedirect) { + res.clearCookie('loginRedirect') + res.redirect(loginRedirect) + } else if (authResult.redirect) { + res.redirect(authResult.redirect) + } else { + res.redirect('/') + } } catch (err) { next(err) }