feat: allow user to redirect after signin (#40069)

Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com>
This commit is contained in:
Oliver Eyton-Williams
2020-11-02 11:10:43 +01:00
committed by GitHub
parent 0dba9c1036
commit a7eba00690
4 changed files with 15 additions and 57 deletions

View File

@@ -1,37 +0,0 @@
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();
};
}