<commit_before>const errors = require('@feathersjs/errors');
const jwt = require('jsonwebtoken');

module.exports = (req, res, next) => {

	// Check if jwt is available, if not let request pass
	if (req.headers.authorization) {
		const decodedToken = jwt.decode(req.headers.authorization.replace('Bearer ', ''));
		const tokenJti = decodedToken.jti; // UID of the token 

		// Check if JTI is in white list and still valid (with redis)

		// Update JTI valid time
	}

	next();
};
<commit_msg>Basic implementation. missing: - add jwt to redis after successful authentication - move check to authentication hook - use a single connection to redis and not establish and close every time<commit_after>const errors = require('@feathersjs/errors');
const redis = require('redis');
const jwt = require('jsonwebtoken');

module.exports = async (req, res, next) => {
	// Connect to redis if defined
	let redisClient = false;
	const redisUrl = process.env.REDIS_URI;
	if (redisUrl) {
		redisClient = redis.createClient({
			url: redisUrl,
		});
	}

	// Check if jwt is available, if not let request pass
	if (redisClient && req.headers.authorization) {
		const decodedToken = jwt.decode(req.headers.authorization.replace('Bearer ', ''));
		const { accountId, jti } = decodedToken; // jti - UID of the token

		const redisIdentifier = `jwt:${accountId}:${jti}`;

		redisClient.on('connect', async () => {
			redisClient.get(redisIdentifier, (err, redisResponse) => {
				if (redisResponse) {
					// Check if JTI is in white list and still valid
					redisClient.set(redisIdentifier, '{"IP": "NONE", "Browser": "NONE"}', 'EX', 100);
				} else {
					// Throw not Authenticated
					redisClient.quit();
					throw new errors.NotAuthenticated('jwt is not whitelisted anymore - autologout');
				}
			});
		});

		// client.set('account:uuid', '{"jtis": [jwt:uuid:jti]}', 'EX', NEVER);
	}

	if (redisClient) {
		// redisClient.quit();
	}

	next();
};

{'fraction_non_alphanumeric': 0.14447884416924664, 'fraction_numerical': 0.0015479876160990713, 'mean_word_length': 3.8354114713216956, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2629102', 'n_tokens_mistral': 694, 'n_tokens_neox': 625, 'n_words': 181}