diff --git a/Parse-Dashboard/Authentication.js b/Parse-Dashboard/Authentication.js index 2f003c3c49..53f2b05b17 100644 --- a/Parse-Dashboard/Authentication.js +++ b/Parse-Dashboard/Authentication.js @@ -67,11 +67,17 @@ function initialize(app, options) { app.post('/login', csrf(), - passport.authenticate('local', { - successRedirect: `${self.mountPath}apps`, - failureRedirect: `${self.mountPath}login`, - failureFlash : true - }) + (req,res,next) => { + let redirect = 'apps'; + if (req.body.redirect) { + redirect = req.body.redirect.charAt(0) === '/' ? req.body.redirect.substring(1) : req.body.redirect + } + return passport.authenticate('local', { + successRedirect: `${self.mountPath}${redirect}`, + failureRedirect: `${self.mountPath}login${req.body.redirect ? `?redirect=${req.body.redirect}` : ''}`, + failureFlash : true + })(req, res, next) + }, ); app.get('/logout', function(req, res){ diff --git a/Parse-Dashboard/app.js b/Parse-Dashboard/app.js index ed03d51f70..56ac3146f0 100644 --- a/Parse-Dashboard/app.js +++ b/Parse-Dashboard/app.js @@ -173,8 +173,9 @@ module.exports = function(config, options) { } app.get('/login', csrf(), function(req, res) { + const redirectURL = req.url.includes('?redirect=') && req.url.split('?redirect=')[1]; if (!users || (req.user && req.user.isAuthenticated)) { - return res.redirect(`${mountPath}apps`); + return res.redirect(`${mountPath}${redirectURL || 'apps'}`); } let errors = req.flash('error'); @@ -206,7 +207,7 @@ module.exports = function(config, options) { // For every other request, go to index.html. Let client-side handle the rest. app.get('/*', function(req, res) { if (users && (!req.user || !req.user.isAuthenticated)) { - return res.redirect(`${mountPath}login`); + return res.redirect(`${mountPath}login?redirect=${req.url.replace('/login', '')}`); } if (users && req.user && req.user.matchingUsername ) { res.append('username', req.user.matchingUsername); diff --git a/src/login/Login.js b/src/login/Login.js index 79f4de1b23..967da8b57e 100644 --- a/src/login/Login.js +++ b/src/login/Login.js @@ -28,10 +28,13 @@ export default class Login extends React.Component { } } + const url = new URL(window.location); + const redirect = url.searchParams.get('redirect'); this.state = { forgot: false, username: sessionStorage.getItem('username') || '', - password: sessionStorage.getItem('password') || '' + password: sessionStorage.getItem('password') || '', + redirect }; sessionStorage.clear(); setBasePath(props.path); @@ -106,6 +109,11 @@ export default class Login extends React.Component { ref={this.inputRefPass} /> } /> + {this.state.redirect && } { this.errors && this.errors.includes('one-time') ?