From 0a31de8125b4050dca9d805423252738c14b982d Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 19 Jul 2021 19:03:16 +0200 Subject: Redirect to original URL after being prompted to log in. --- server.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'server.js') diff --git a/server.js b/server.js index 7c9de8e..e220d46 100644 --- a/server.js +++ b/server.js @@ -268,8 +268,10 @@ function update_last_seen(req) { } function must_be_logged_in(req, res, next) { - if (!req.isAuthenticated()) + if (!req.isAuthenticated()) { + req.session.redirect = req.originalUrl; return res.redirect('/login'); + } if (sql_blacklist_ip.get(req.connection.remoteAddress)[0] !== 0) return res.redirect('/banned'); if (sql_blacklist_mail.get(req.user.mail)[0] !== 0) @@ -309,10 +311,14 @@ app.get('/signup', function (req, res) { app.post('/login', passport.authenticate('local-login', { - successRedirect: '/profile', failureRedirect: '/login', failureFlash: true - }) + }), + (req, res) => { + let redirect = req.session.redirect || '/profile'; + delete req.session.redirect; + res.redirect(redirect); + } ); app.post('/signup', -- cgit v1.2.3