import { Response, NextFunction } from 'express'; import { verifyToken } from '../config/jwt'; export const protect = (req: any, res: any, next: NextFunction) => { const token = req.headers.authorization?.split(' ')[1]; if (!token) { return res.status(401).json({ message: 'Auth token missing' }); } try { const decoded = verifyToken(token); req.user = decoded; next(); } catch (error) { res.status(401).json({ message: 'Invalid token' }); } };