Bansari Akhani
location api for AI service - #8264, fix #8263, remove debug console
c2bc2d7
raw
history blame contribute delete
664 Bytes
import { Response, NextFunction } from 'express';
import { verifyToken } from '../utils/jwtUtils';
import { AuthenticatedRequest, UserInterface } from '../shared/interfaces/user.interface';
const jwtMiddleware = (req: AuthenticatedRequest, res: Response, next: NextFunction) => {
const token = req.header('authorization')?.split(' ')[1];
if (!token) {
return res.status(401).json({ error: 'Unauthorized' });
}
try {
const user = verifyToken(token);
req.user = user as UserInterface;
next();
} catch (error) {
return res.status(401).json({ error: 'Unauthorized' });
}
}
export {jwtMiddleware}