Änderungen am TAgebuch

This commit is contained in:
Torsten Schulz
2024-08-30 11:50:54 +02:00
parent 828035d339
commit 1ac1fc9ca0
116 changed files with 6859 additions and 6765 deletions

View File

@@ -1,13 +1,17 @@
import User from '../models/User.js';
export const authenticate = async (req, res, next) => {
const { userid: userId, authcode: authCode } = req.headers;
if (!userId || !authCode) {
return res.status(401).json({ error: 'Unauthorized: Missing credentials' });
try {
const { userid: userId, authcode: authCode } = req.headers;
if (!userId || !authCode) {
return res.status(401).json({ error: 'Unauthorized: Missing credentials' });
}
const user = await User.findOne({ where: { email: userId, authCode: authCode } });
if (!user) {
return res.status(401).json({ error: 'Unauthorized: Invalid credentials' });
}
next();
} catch(error) {
return res.status(500).json({ error: 'Internal Server Error at auth' });
}
const user = await User.findOne({ where: { email: userId, hashedId: authCode } });
if (!user) {
return res.status(401).json({ error: 'Unauthorized: Invalid credentials' });
}
next();
};