fix: register returnTo logic to match login route

Login route saves the previous page by checking for the X-Return-To header. This header is automatically set by ajaxify.
Login takes this value and saves it to `req.session`.

Up until now, `/register` saved the previous URL in a hidden input, and redirected based on that value, but it occasionally conflicted with req.session.returnTo. It was also confusing because it did not match how login handled the values.

This commit updates the route handling so it works identically to `/login`.
This commit is contained in:
Julian Lam
2021-02-05 11:05:21 -05:00
parent 9576bec6c3
commit 67e3fb6498
3 changed files with 12 additions and 11 deletions

View File

@@ -144,6 +144,7 @@ Controllers.register = async function (req, res, next) {
}
let errorText;
const returnTo = (req.headers['x-return-to'] || '').replace(nconf.get('base_url') + nconf.get('relative_path'), '');
if (req.query.error === 'csrf-invalid') {
errorText = '[[error:csrf-invalid]]';
}
@@ -158,6 +159,10 @@ Controllers.register = async function (req, res, next) {
}
}
if (returnTo) {
req.session.returnTo = returnTo;
}
const loginStrategies = require('../routes/authentication').getLoginStrategies();
res.render('register', {
'register_window:spansize': loginStrategies.length ? 'col-md-6' : 'col-md-12',