Redis and session timeout added

This commit is contained in:
Torsten Schulz
2024-10-27 14:15:44 +01:00
parent 7f8709516d
commit b78dfe6826
9 changed files with 320 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
import User from '../models/community/user.js';
import { updateUserTimestamp } from '../utils/redis.js';
export const authenticate = async (req, res, next) => {
const userId = req.headers.userid;
@@ -6,11 +7,14 @@ export const authenticate = async (req, res, next) => {
if (!userId || !authCode) {
return res.status(401).json({ error: 'Unauthorized: Missing credentials' });
}
const user = await User.findOne({ where: { hashedId: userId, authCode } });
if (!user) {
return res.status(401).json({ error: 'Unauthorized: Invalid credentials' });
}
try {
await updateUserTimestamp(userId);
} catch (error) {
console.error('Fehler beim Aktualisieren des Zeitstempels:', error);
}
next();
};