21 lines
728 B
JavaScript
21 lines
728 B
JavaScript
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;
|
|
const authCode = req.headers.authcode;
|
|
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();
|
|
};
|