Skip to content

Commit

Permalink
Merge pull request #52 from Amsterdam/bugfix/flash-save-session-befor…
Browse files Browse the repository at this point in the history
…e-redirect

Bugfix/flash save session before redirect
  • Loading branch information
nlsvgtr authored May 19, 2022
2 parents 033e508 + 5bb393a commit ff369ca
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 129 deletions.
6 changes: 4 additions & 2 deletions middleware/request/validation/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ module.exports = (req, res, next) => {

if (errors.length > 0) {
req.flash('error', { msg: errors.join(',')});
const redirectUrl = getRefererUrl(req.header('Referer'));
return res.redirect(redirectUrl);
req.session.save( () => {
const redirectUrl = getRefererUrl(req.header('Referer'));
return res.redirect(redirectUrl);
});
}

next();
Expand Down
123 changes: 45 additions & 78 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion routes/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ module.exports = function(app){
const ingresses = await ingress.ensureIngressForAllDomains(req.sites);

req.flash('success', { msg: 'Checked ingress' });
res.redirect('/admin/server');
req.session.save( () => {
res.redirect('/admin/server');
});
}
);

Expand Down
4 changes: 3 additions & 1 deletion routes/site/idea-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ module.exports = function(app){
(req, res, next) => {
if (req.ideas.length === 0) {
req.flash('error', { msg: 'No ideas to export'});
res.redirect(req.header('Referer'));
req.session.save( () => {
res.redirect(req.header('Referer'));
});
} else {
const exportHeaders = [
{key: 'id', label: 'ID'},
Expand Down
10 changes: 7 additions & 3 deletions routes/site/idea-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,18 @@ module.exports = function(app){
Promise.all(promises)
.then(function (response) {
req.flash('success', { msg: 'Geimporteerd!'});
res.redirect(`/admin/site/${req.params.siteId}/ideas`);
// res.redirect(redirectTo);
req.session.save( () => {
res.redirect(`/admin/site/${req.params.siteId}/ideas`);
// res.redirect(redirectTo);
});
})
.catch(function (err) {
console.log('errerrerrerr', err);
let message = err && err.error && err.error.message ? 'Er gaat iets mis: '+ err.error.message : 'Er gaat iets mis!';
req.flash('error', { msg: message});
res.redirect(req.header('Referer') || appUrl);
req.session.save( () => {
res.redirect(req.header('Referer') || appUrl);
});
});
}
);
Expand Down
18 changes: 12 additions & 6 deletions routes/site/idea.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ module.exports = function(app){
})
.catch(function (err) {
let message = err && err.error && err.error.message ? 'Er gaat iets mis: '+ err.error.message : 'Er gaat iets mis!';
req.flash('error', { msg: message});
res.redirect(req.header('Referer') || appUrl);
req.flash('error', { msg: message});
req.session.save( () => {
res.redirect(req.header('Referer') || appUrl);
});
});
}
);
Expand Down Expand Up @@ -133,14 +135,18 @@ module.exports = function(app){
ideaApi
.create(req.session.jwt, req.params.siteId, idea)
.then(function (response) {
req.flash('success', { msg: 'Aangemaakt!'});
res.redirect(`/admin/site/${req.params.siteId}/ideas`);
res.redirect(redirectTo);
req.flash('success', { msg: 'Aangemaakt!'});
req.session.save( () => {
res.redirect(`/admin/site/${req.params.siteId}/ideas`);
res.redirect(redirectTo);
});
})
.catch(function (err) {
let message = err && err.error && err.error.message ? 'Er gaat iets mis: '+ err.error.message : 'Er gaat iets mis!';
req.flash('error', { msg: message});
res.redirect(req.header('Referer') || appUrl);
req.session.save( () => {
res.redirect(req.header('Referer') || appUrl);
});
});
}
);
Expand Down
4 changes: 3 additions & 1 deletion routes/site/newsletter.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ module.exports = function(app){
(req, res, next) => {
if (req.newsletterSubsribers.length === 0) {
req.flash('error', { msg: 'No subscribers to export'});
res.redirect(req.header('Referer'));
req.session.save( () => {
res.redirect(req.header('Referer'));
});
} else {
const exportHeaders = [
{key: 'id', label: 'ID'},
Expand Down
Loading

0 comments on commit ff369ca

Please sign in to comment.