parse-dashboard 5.1.0-alpha.4 → 5.1.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -67,11 +67,17 @@ function initialize(app, options) {
67
67
 
68
68
  app.post('/login',
69
69
  csrf(),
70
- passport.authenticate('local', {
71
- successRedirect: `${self.mountPath}apps`,
72
- failureRedirect: `${self.mountPath}login`,
73
- failureFlash : true
74
- })
70
+ (req,res,next) => {
71
+ let redirect = 'apps';
72
+ if (req.body.redirect) {
73
+ redirect = req.body.redirect.charAt(0) === '/' ? req.body.redirect.substring(1) : req.body.redirect
74
+ }
75
+ return passport.authenticate('local', {
76
+ successRedirect: `${self.mountPath}${redirect}`,
77
+ failureRedirect: `${self.mountPath}login${req.body.redirect ? `?redirect=${req.body.redirect}` : ''}`,
78
+ failureFlash : true
79
+ })(req, res, next)
80
+ },
75
81
  );
76
82
 
77
83
  app.get('/logout', function(req, res){
@@ -173,8 +173,9 @@ module.exports = function(config, options) {
173
173
  }
174
174
 
175
175
  app.get('/login', csrf(), function(req, res) {
176
+ const redirectURL = req.url.includes('?redirect=') && req.url.split('?redirect=')[1];
176
177
  if (!users || (req.user && req.user.isAuthenticated)) {
177
- return res.redirect(`${mountPath}apps`);
178
+ return res.redirect(`${mountPath}${redirectURL || 'apps'}`);
178
179
  }
179
180
 
180
181
  let errors = req.flash('error');
@@ -206,7 +207,7 @@ module.exports = function(config, options) {
206
207
  // For every other request, go to index.html. Let client-side handle the rest.
207
208
  app.get('/*', function(req, res) {
208
209
  if (users && (!req.user || !req.user.isAuthenticated)) {
209
- return res.redirect(`${mountPath}login`);
210
+ return res.redirect(`${mountPath}login?redirect=${req.url.replace('/login', '')}`);
210
211
  }
211
212
  if (users && req.user && req.user.matchingUsername ) {
212
213
  res.append('username', req.user.matchingUsername);