File size: 762 Bytes
51dd86d
 
 
27113f7
 
 
 
51dd86d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27113f7
51dd86d
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const Settings = require('../models/Settings');

const authMiddleware = async (req, res, next) => {
    // Authentication disabled for public shop API
    next();

    /* Original auth code (disabled):
    try {
        const apiKey = req.headers['x-api-key'];

        if (!apiKey) {
            return res.status(401).json({ error: 'API Key missing' });
        }

        const validKey = await Settings.findOne({ key: 'api_secret_key' });

        if (!validKey || validKey.value !== apiKey) {
            return res.status(403).json({ error: 'Invalid API Key' });
        }

        next();
    } catch (e) {
        console.error("Auth Error:", e);
        res.status(500).json({ error: 'Server Error' });
    }
    */
};

module.exports = authMiddleware;