Separated weight tracking
This commit is contained in:
21
server/src/middleware/auth.ts
Normal file
21
server/src/middleware/auth.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import jwt from 'jsonwebtoken';
|
||||
|
||||
const JWT_SECRET = process.env.JWT_SECRET || 'secret';
|
||||
|
||||
export const authenticateToken = (req: Request, res: Response, next: NextFunction) => {
|
||||
const authHeader = req.headers['authorization'];
|
||||
const token = authHeader && authHeader.split(' ')[1];
|
||||
|
||||
if (!token) {
|
||||
return res.sendStatus(401);
|
||||
}
|
||||
|
||||
jwt.verify(token, JWT_SECRET, (err: any, user: any) => {
|
||||
if (err) {
|
||||
return res.sendStatus(403);
|
||||
}
|
||||
(req as any).user = user;
|
||||
next();
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user