0
我目前在项目上使用sean.js。一切看起来不错,但我在注册过程中遇到了问题。我最近实施的对我的路线后端的政策,给予权限,我的用户根据自己的角色,这样的事情:SEAN.js注册后自动注册和req.user.roles
exports.invokeRolesPolicies = function() {
acl.allow([{
roles: ['myRole'],
allows: [{
resources: '/some-route',
permissions: '*'
}]
}]);
};
exports.isAllowed = function (req, res, next) {
var roles = (req.user) ? req.user.roles : ['guest'];
// If an person is being processed and the current user created it then allow any manipulation
if (req.people && req.user && req.people.user && req.people.user.id === req.user.id) {
return next();
}
// Check for user roles
acl.areAnyRolesAllowed(roles, req.route.path, req.method.toLowerCase(), function (err, isAllowed) {
if (err) {
// An authorization error occurred
return res.status(500).send('Unexpected authorization error');
} else {
if (isAllowed) {
// Access granted! Invoke next middleware
return next();
} else {
return res.status(403).json({
message: 'User is not authorized'
});
}
}
});
};
我用自带的SEAN模板的,它使用ACL设置权限。此方法在您的用户登录时正常工作。
问题是,当我从注册表单创建一个新用户时,它会自动登录到系统上,但它没有得到与它的角色,并且req.user.roles为空。我有一个过程,在注册后用户需要完成另一个表单来设置所有内容,但是由于角色问题,策略无法识别角色并给出“访客”角色,导致我无法访问我的路由。如果我在注册自动登录后注销,则一切正常,因为现在角色设置正常。
我需要在redis服务器上设置其他的东西吗?或者我需要做什么?