Some udpates to tracking user inputs. Still not happy with it but functional so moving on
This commit is contained in:
@@ -1,7 +1,19 @@
|
||||
const logger = require('../utils/logger');
|
||||
|
||||
const requireAuth = (req, res, next) => {
|
||||
if (req.session && req.session.authenticated) {
|
||||
// Check for both authentication patterns used in your app
|
||||
const isAuthenticated = (req.session && req.session.authenticated) ||
|
||||
(req.session && req.session.userId && req.session.userEmail);
|
||||
|
||||
if (isAuthenticated) {
|
||||
next();
|
||||
} else {
|
||||
logger.warn('Unauthorized access attempt', {
|
||||
ip: req.ip,
|
||||
path: req.path,
|
||||
userAgent: req.get('User-Agent')
|
||||
});
|
||||
|
||||
if (req.xhr || req.headers.accept?.indexOf('json') > -1) {
|
||||
res.status(401).json({
|
||||
success: false,
|
||||
@@ -14,9 +26,20 @@ const requireAuth = (req, res, next) => {
|
||||
};
|
||||
|
||||
const requireAdmin = (req, res, next) => {
|
||||
if (req.session && req.session.authenticated && req.session.isAdmin) {
|
||||
// Check for both authentication patterns used in your app
|
||||
const isAuthenticated = (req.session && req.session.authenticated) ||
|
||||
(req.session && req.session.userId && req.session.userEmail);
|
||||
|
||||
if (isAuthenticated && req.session.isAdmin) {
|
||||
next();
|
||||
} else {
|
||||
logger.warn('Unauthorized admin access attempt', {
|
||||
ip: req.ip,
|
||||
path: req.path,
|
||||
user: req.session?.userEmail || 'anonymous',
|
||||
userAgent: req.get('User-Agent')
|
||||
});
|
||||
|
||||
if (req.xhr || req.headers.accept?.indexOf('json') > -1) {
|
||||
res.status(403).json({
|
||||
success: false,
|
||||
|
||||
Reference in New Issue
Block a user