Skip to content

Commit aac9997

Browse files
committed
fix: have adjustRelogin only function for cold loads, use client-side hook for relogin hijack on ajaxify instead
1 parent 065963c commit aac9997

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

lib/controllers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Controllers.renderTotpChallenge = async (req, res, next) => {
7070
const uid = res.locals['2factor'] || req.uid;
7171
const single = parseInt(req.query.single, 10) === 1;
7272

73-
if (req.session.tfa === true && ((req.query.next && !req.query.next.startsWith('/admin')) || !req.session.tfaForce)) {
73+
if (req.session.tfa === true && !req.session.tfaForce) {
7474
return res.redirect(nconf.get('relative_path') + (req.query.next || '/'));
7575
}
7676

@@ -248,6 +248,6 @@ Controllers.renderAccessNotificationHelp = (req, res, next) => {
248248
timeString: date.toLocaleTimeString(date),
249249
dateString: date.toLocaleDateString(date),
250250
});
251-
}
251+
};
252252

253253
module.exports = Controllers;

library.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ plugin.init = async (params) => {
105105
plugin.exemptions = {
106106
prefixes,
107107
paths: new Set(pages.concat(paths)),
108-
}
108+
};
109109
};
110110

111111
plugin.addRoutes = async ({ router, middleware, helpers }) => {
@@ -412,7 +412,10 @@ plugin.adjustRelogin = async ({ req, res }) => {
412412
if (await plugin.hasKey(req.uid)) {
413413
req.session.forceLogin = 0;
414414
req.session.tfaForce = 1;
415-
controllerHelpers.redirect(res, `/login/2fa?next=${req.session.returnTo}`);
415+
416+
if (!res.locals.isAPI) {
417+
controllerHelpers.redirect(res, `/login/2fa?next=${req.session.returnTo}`);
418+
}
416419
}
417420
};
418421

@@ -426,7 +429,7 @@ plugin.handle2faFailure = async (uid) => {
426429
});
427430

428431
await notifications.push(notification, [uid]);
429-
}
432+
};
430433

431434
plugin.integrations = {};
432435

plugin.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
"scss": [
2222
"static/style.scss"
2323
],
24+
"scripts": [
25+
"static/lib/main.js"
26+
],
2427
"modules": {
2528
"../admin/plugins/2factor.js": "./static/lib/admin.js",
2629
"../client/login-totp.js": "./static/lib/totp.js",

static/lib/main.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
(async () => {
4+
const hooks = await app.require('hooks');
5+
hooks.on('filter:admin.reauth', (data) => {
6+
data.url = `/login/2fa?next=/${ajaxify.currentPage}`;
7+
return data;
8+
});
9+
})();

0 commit comments

Comments
 (0)