revert: allow user to redirect after signin (#40160)

This reverts commit a7eba00690.
This commit is contained in:
Mrugesh Mohapatra
2020-11-02 19:24:24 +05:30
committed by GitHub
parent e6b29dcc2c
commit 5f67843e50
4 changed files with 57 additions and 15 deletions

View File

@@ -0,0 +1,37 @@
const pathsOfNoReturn = [
'link',
'auth',
'login',
'logout',
'signin',
'signup',
'fonts',
'favicon',
'js',
'css'
];
const pathsAllowedList = ['challenges', 'map', 'commit'];
const pathsOfNoReturnRegex = new RegExp(pathsOfNoReturn.join('|'), 'i');
const pathsAllowedRegex = new RegExp(pathsAllowedList.join('|'), 'i');
export default function addReturnToUrl() {
return function(req, res, next) {
// Remember original destination before login.
var path = req.path.split('/')[1];
if (
req.method !== 'GET' ||
pathsOfNoReturnRegex.test(path) ||
!pathsAllowedRegex.test(path) ||
/hot/i.test(req.path)
) {
return next();
}
req.session.returnTo = req.originalUrl.includes('/map')
? '/'
: req.originalUrl;
return next();
};
}