@@ -4,7 +4,10 @@ const authMiddleware = (req, res, next) => {
|
|||||||
const JWT_SECRET = 'secretkey';
|
const JWT_SECRET = 'secretkey';
|
||||||
const authHeader = req.headers.authorization;
|
const authHeader = req.headers.authorization;
|
||||||
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
||||||
return res.status(401).json({ error: 'Unauthorized: Missing or invalid token format' });
|
return res.status(401).json({
|
||||||
|
success: false,
|
||||||
|
message: 'Unauthorized: Missing or invalid token format'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
const token = authHeader.split(' ')[1];
|
const token = authHeader.split(' ')[1];
|
||||||
try {
|
try {
|
||||||
@@ -12,8 +15,11 @@ const JWT_SECRET = 'secretkey';
|
|||||||
req.user = decoded;
|
req.user = decoded;
|
||||||
next();
|
next();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
return res.status(401).json({
|
||||||
|
success: false,
|
||||||
|
message: 'Unauthorized: Invalid token'
|
||||||
|
});
|
||||||
|
|
||||||
return res.status(401).json({ error: 'Unauthorized: Invalid token' });
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user