From f13e6b0e16165e8bcabe7d601859ca796115a56d Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Tue, 25 Jul 2017 12:38:49 +1000 Subject: [PATCH] Fixes to impl --- app.js | 2 +- services/passport.js | 5 +++-- services/users.js | 8 +++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app.js b/app.js index d7f46ceef..a6b669b0e 100644 --- a/app.js +++ b/app.js @@ -101,7 +101,7 @@ app.use('/api', authentication); app.use('/api', (req, res, next) => { // Attach the pubsub handle to the requests. - req.pubsub = pubsub(); + req.pubsub = pubsub.createClient(); // Forward on the request. next(); diff --git a/services/passport.js b/services/passport.js index 9fc2631b0..acf3043a9 100644 --- a/services/passport.js +++ b/services/passport.js @@ -14,6 +14,7 @@ const ms = require('ms'); // Create a redis client to use for authentication. const {createClientFactory} = require('./redis'); +const client = createClientFactory(); const { JWT_SECRET, @@ -147,7 +148,7 @@ const HandleLogout = (req, res, next) => { const now = new Date(); const expiry = (jwt.exp - now.getTime() / 1000).toFixed(0); - createClientFactory().set(`jtir[${jwt.jti}]`, now.toISOString(), 'EX', expiry, (err) => { + client().set(`jtir[${jwt.jti}]`, now.toISOString(), 'EX', expiry, (err) => { if (err) { return next(err); } @@ -158,7 +159,7 @@ const HandleLogout = (req, res, next) => { }; const checkGeneralTokenBlacklist = (jwt) => new Promise((resolve, reject) => { - createClientFactory().get(`jtir[${jwt.jti}]`, (err, expiry) => { + client().get(`jtir[${jwt.jti}]`, (err, expiry) => { if (err) { return reject(err); } diff --git a/services/users.js b/services/users.js index 83a8c3cbe..12da5ecce 100644 --- a/services/users.js +++ b/services/users.js @@ -32,6 +32,8 @@ const SALT_ROUNDS = 10; // Create a redis client to use for authentication. const {createClientFactory} = require('./redis'); +const client = createClientFactory(); + // UsersService is the interface for the application to interact with the // UserModel through. module.exports = class UsersService { @@ -67,7 +69,7 @@ module.exports = class UsersService { const rdskey = `la[${email.toLowerCase().trim()}]`; return new Promise((resolve, reject) => { - createClientFactory() + client() .multi() .incr(rdskey) .expire(rdskey, RECAPTCHA_WINDOW_SECONDS) @@ -80,7 +82,7 @@ module.exports = class UsersService { if (replies[0] === 1 || replies[1] === -1) { // then expire it after the timeout - createClientFactory().expire(rdskey, RECAPTCHA_WINDOW_SECONDS); + client().expire(rdskey, RECAPTCHA_WINDOW_SECONDS); } if (replies[0] >= RECAPTCHA_INCORRECT_TRIGGER) { @@ -102,7 +104,7 @@ module.exports = class UsersService { const rdskey = `la[${email.toLowerCase().trim()}]`; return new Promise((resolve, reject) => { - createClientFactory() + client() .get(rdskey, (err, reply) => { if (err) { return reject(err);