nodebb-plugin-session-sharing 8.0.1 → 8.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/library.js +18 -5
- package/package.json +1 -1
package/library.js
CHANGED
|
@@ -367,11 +367,19 @@ async function executeJoinLeave(uid, join, leave) {
|
|
|
367
367
|
}
|
|
368
368
|
|
|
369
369
|
plugin.createUser = async (userData) => {
|
|
370
|
-
|
|
370
|
+
const count = await db.incrObjectField('locks', `session-sharing-create:${userData.id}`);
|
|
371
|
+
if (count > 1) {
|
|
372
|
+
throw new Error('duplicate-creation');
|
|
373
|
+
}
|
|
374
|
+
try {
|
|
375
|
+
winston.verbose('[session-sharing] No user found, creating a new user for this login');
|
|
371
376
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
377
|
+
const uid = await user.create(_.pick(userData, profileFields));
|
|
378
|
+
await db.sortedSetAdd(plugin.settings.name + ':uid', uid, userData.id);
|
|
379
|
+
return uid;
|
|
380
|
+
} finally {
|
|
381
|
+
await db.deleteObjectFields('locks', [`session-sharing-create:${userData.id}`]);
|
|
382
|
+
}
|
|
375
383
|
};
|
|
376
384
|
|
|
377
385
|
plugin.addMiddleware = async function ({ req, res }) {
|
|
@@ -447,7 +455,9 @@ plugin.addMiddleware = async function ({ req, res }) {
|
|
|
447
455
|
const uid = await plugin.process(req.cookies[plugin.settings.cookieName]);
|
|
448
456
|
if (uid === req.uid) {
|
|
449
457
|
winston.verbose(`[session-sharing] Re-validated login for uid ${uid}, path ${req.originalUrl}`);
|
|
450
|
-
|
|
458
|
+
const wasForceLogin = !!req.session.forceLogin;
|
|
459
|
+
delete req.session.forceLogin;
|
|
460
|
+
await nbbAuthController.onSuccessfulLogin(req, uid, true, wasForceLogin);
|
|
451
461
|
return;
|
|
452
462
|
}
|
|
453
463
|
|
|
@@ -469,6 +479,9 @@ plugin.addMiddleware = async function ({ req, res }) {
|
|
|
469
479
|
winston.info('[session-sharing] Payload valid, but local account not found. Assuming guest.');
|
|
470
480
|
handleAsGuest = true;
|
|
471
481
|
break;
|
|
482
|
+
case 'duplicate-creation':
|
|
483
|
+
winston.warn('[session-sharing] Duplicate account creation attempt detected');
|
|
484
|
+
break;
|
|
472
485
|
default:
|
|
473
486
|
winston.warn('[session-sharing] Error encountered while parsing token: ' + error.message);
|
|
474
487
|
break;
|