mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +01:00
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:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user