{
userId: string;
history: videoID[];
}
export function jwt_authentication_controller(req: Request, res: Response, next: NextFunction) {
const header = req.headers['authentication'];
const JWT_secret = process.env['JWT_SECRET'];
if(JWT_secret) {
JWT.verify(header?.toString() || '', JWT_secret, (err, data) => {
if(err) {
console.log(err);
if(req.originalUrl !== '/auth') res.redirect('/auth');
else next();
return;
}
res.locals['user'] = data;
return next();
});
return;
}
res.sendStatus(502);
res.end();
return;
}