Fixes to impl

This commit is contained in:
Wyatt Johnson
2017-07-25 12:38:49 +10:00
parent c2f6b9aa09
commit f13e6b0e16
3 changed files with 9 additions and 6 deletions
+1 -1
View File
@@ -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();
+3 -2
View File
@@ -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);
}
+5 -3
View File
@@ -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);