const jwt = require('jsonwebtoken');
class Authorized {
constructor() {
this.secretKey = 'dSjkLsSjerIfkL';
}
createSign(data, secretKey){
return jwt.sign(data,secretKey)
}
isAuthorized(req, res, next){
if (typeof req.headers.token !== "undefined") {
const token = req.headers.token.split(' ')[1]
jwt.verify(token, this.secretKey, {
algorithms: 'HS256'
}, (err, decoded) => {
if (err) {
res.status(500).json({
error: 'No authorized'
})
}
next()
})
} else {
console.log('No authorized')
}
}
}
module.exports = new Authorized();
ReferenceError: jwt is not defined
означает отсутствие переменнойclass Authorized {
...
}
module.exports = new Authorized();
const auth = require('../moduls/authorized')
// moduls ? может быть modules?
gulp.task('compress', function() {
return gulp.src('app/js/*.js')
.pipe(uglify())
.pipe(gulp.dest('prodact/assets/js/'));
});