mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: introduce boolean res.locals flag to bypass session reroll (used by session-sharing)
The session reroll logic is still standard practice, but in some cases, it is not necessary or causes UX issues. An issue opened in session sharing (julianlam/nodebb-plugin-session-sharing#95) brought this to attention in that parsing the cookie to log in the user caused a reroll (as expected), but caused the session open on other tabs to be mismatched. If "re-validate" was turned on, it basically meant that it was not possible to use NodeBB with multiple tabs. Session sharing now sets `reroll` to `false` if re-validate is enabled.
This commit is contained in:
@@ -326,12 +326,16 @@ authenticationController.doLogin = async function (req, uid) {
|
||||
return;
|
||||
}
|
||||
const loginAsync = util.promisify(req.login).bind(req);
|
||||
const regenerateSession = util.promisify(req.session.regenerate).bind(req.session);
|
||||
|
||||
const sessionData = { ...req.session };
|
||||
await regenerateSession();
|
||||
for (const [prop, value] of Object.entries(sessionData)) {
|
||||
req.session[prop] = value;
|
||||
const { reroll } = req.res.locals;
|
||||
if (reroll !== false) {
|
||||
const regenerateSession = util.promisify(req.session.regenerate).bind(req.session);
|
||||
|
||||
const sessionData = { ...req.session };
|
||||
await regenerateSession();
|
||||
for (const [prop, value] of Object.entries(sessionData)) {
|
||||
req.session[prop] = value;
|
||||
}
|
||||
}
|
||||
|
||||
await loginAsync({ uid: uid });
|
||||
|
||||
Reference in New Issue
Block a user