diff options
author | Tor Andersson <tor@ccxvii.net> | 2021-07-19 19:03:16 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2021-07-19 19:12:36 +0200 |
commit | 0a31de8125b4050dca9d805423252738c14b982d (patch) | |
tree | cb38339de253d8181d341481f0c88211ad43dd46 | |
parent | 76da927e841af2de8c47f2d0a177ecebb9c5b5f8 (diff) | |
download | server-0a31de8125b4050dca9d805423252738c14b982d.tar.gz |
Redirect to original URL after being prompted to log in.
-rw-r--r-- | server.js | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -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', |