-1
노드와 각도를 사용하여 JWT로 토큰을 생성했으며 사용자가 권한이 있는지 확인할 수 없습니다.각도로 사용자 토큰을 확인하는 방법은 무엇입니까?
노드 :
module.exports.authenticate = function(req, res) {
var user = new User(req.body);
User.findOne({
username: req.body.username
}, function(err, user) {
if (err) throw err;
if (!user) {
res.json({ success: false, message: 'Authentication failed. User not found.' });
}
else if (user) {
if (user.password != req.body.password) {
res.json({ success: false, message: 'Authentication failed. Wrong password.' });
}
else {
var token = jwt.sign(user, config.secret, {
expiresIn: 60*60*24
});
res.json({
success: true,
token: token
});
}
}
});
};
각도 : 나는 경로를 변경할 때
$http(req)
.then(function (response) {
console.log(response.data.success);
if(response.data.success) {
var user = localStorage.setItem('token', JSON.stringify(response.data));
token = localStorage.getItem('token');
// console.log('User info: ', JSON.parse(getuser));
// window.location = "/dashboard";
return response.data;
}
}, function (response) {
}
);
}
가 어떻게 토큰을 확인할 수 있습니다
?일반적으로 어떻게 토큰을 사용할 수 있습니까?