fix Analyse
This commit is contained in:
@@ -20,17 +20,19 @@ app.use((req, res, next) => {
|
||||
if (req.method === 'OPTIONS' || !req.path.startsWith('/api/')) return next();
|
||||
if (req.path.startsWith('/api/analytics')) return next();
|
||||
|
||||
let userId = null;
|
||||
const authHeader = req.headers.authorization;
|
||||
if (authHeader && authHeader.startsWith('Bearer ')) {
|
||||
try {
|
||||
const decoded = jwt.verify(authHeader.split(' ')[1], JWT_SECRET);
|
||||
const user = getUserByUsername(decoded.username);
|
||||
if (user) userId = user.id;
|
||||
} catch {}
|
||||
}
|
||||
try {
|
||||
let userId = null;
|
||||
const authHeader = req.headers.authorization;
|
||||
if (authHeader && authHeader.startsWith('Bearer ')) {
|
||||
try {
|
||||
const decoded = jwt.verify(authHeader.split(' ')[1], JWT_SECRET);
|
||||
const user = getUserByUsername(decoded.username);
|
||||
if (user) userId = user.id;
|
||||
} catch {}
|
||||
}
|
||||
trackEvent('page_view', userId, { path: req.path, method: req.method });
|
||||
} catch {}
|
||||
|
||||
trackEvent('page_view', userId, { path: req.path, method: req.method });
|
||||
next();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user