简体   繁体   English

流星和React的角色

[英]Roles with Meteor and React

I am currently working on a project for a client. 我目前正在为客户开发项目。 I'm trying to assign roles to users at the time they sign up for an account. 我正在尝试在用户注册帐户时为他们分配角色。

handleSubmit(e){
    e.preventDefault();
    this.setState({message:'',messageClass:'hidden'});
    var that = this;
    var first_name = ReactDOM.findDOMNode(this.refs.first_name).value.trim();
    var last_name = ReactDOM.findDOMNode(this.refs.last_name).value.trim();
    var email = ReactDOM.findDOMNode(this.refs.email).value.trim();
    var password = ReactDOM.findDOMNode(this.refs.password).value.trim();
    var type = 'fan';
    var user = {email:email,password:password,profile:{fullname:(first_name + last_name).toLowerCase(),firsname:first_name,lastname:last_name,avatar:'http://placehold.it/150x150',friends:[],type:type}};
    Accounts.createUser(user,function(e){
        if (e) {
            Materialize.toast(e.reason, 5000);
        } else {
            FlowRouter.go('/dashboard');
        }
    })
}

Above is my handle submit event for the signup form. 上面是我的注册表单的handle提交事件。 Below is the hook that I added to assign the role to the user after the user is inserted. 下面是我添加的挂钩,用于在插入用户后为用户分配角色。

Meteor.users.after.insert(function (userId, doc) {
if (doc.profile.type === "fan") {
    Roles.addUsersToRoles(doc._id, [ROLES.Fan])
}

}); });

What I'm finding is that the user gets created but instead of being redirected to the dashboard, the user remains on the signup page and receives an error in the toaster message stating internal server error. 我发现的是,已创建用户,但没有将其重定向到仪表板,而是保留在注册页面上,并在烤面包机消息中收到错误,指出内部服务器错误。 When I go into the console to find the user that was created, the profile type is assigned but the user is missing their email address. 当我进入控制台以查找创建的用户时,分配了个人档案类型,但是该用户缺少其电子邮件地址。

This is the error I'm getting in my terminal window: 这是我在终端窗口中遇到的错误:

Exception while invoking method 'createUser' ReferenceError: ROLES is not defined I20160402-16:04:42.482(-4)? 调用方法'createUser'时发生异常ReferenceError:未定义ROLES I20160402-16:04:42.482(-4)? at Object. 在对象。 (both/collection_hooks/hooks.jsx:3:35) I20160402-16:04:42.482(-4)? (both / collection_hooks / hooks.jsx:3:35)I20160402-16:04:42.482(-4)?
at packages/matb33_collection-hooks/insert.js:35:1 I20160402-16:04:42.482(-4)? 在package / matb33_collection-hooks / insert.js:35:1 I20160402-16:04:42.482(-4)? at Array.forEach (packages/es5-shim/.npm/package/node_modules/es5-shim/es5-shim.js:417:1) I20160402-16:04:42.483(-4)? 在Array.forEach(packages / es5-shim / .npm / package / node_modules / es5-shim / es5-shim.js:417:1)I20160402-16:04:42.483(-4)吗? at Function. 在功能。 .each. 。每。 .forEach (packages/underscore/underscore.js:105:1) I20160402-16:04:42.483(-4)? .forEach(packages / underscore / underscore.js:105:1)I20160402-16:04:42.483(-4)? at after (packages/matb33_collection-hooks/insert.js:34:1) I20160402-16:04:42.483(-4)? 在之后(packages / matb33_collection-hooks / insert.js:34:1)I20160402-16:04:42.483(-4)吗? at Object.CollectionHooks.defineAdvice.self (packages/matb33_collection-hooks/insert.js:49:1) I20160402-16:04:42.485(-4)? 在Object.CollectionHooks.defineAdvice.self(packages / matb33_collection-hooks / insert.js:49:1)I20160402-16:04:42.485(-4)吗? at Object.collection.(anonymous function) [as insert] (packages/matb33_collection-hooks/collection-hooks.js:117:1) I20160402-16:04:42.485(-4)? 在Object.collection。(匿名函数)[作为插入](packages / matb33_collection-hooks / collection-hooks.js:117:1)I20160402-16:04:42.485(-4)? at [object Object].Mongo.Collection.(anonymous function) [as insert] (packages/mongo/collection.js:590:1) I20160402-16:04:42.485(-4)? 在[object Object] .Mongo.Collection。(匿名函数)[作为插入](packages / mongo / collection.js:590:1)I20160402-16:04:42.485(-4)吗?
at AccountsServer.Ap.insertUserDoc (accounts_server.js:1248:25) I20160402-16:04:42.486(-4)? 在AccountsServer.Ap.insertUserDoc(accounts_server.js:1248:25)I20160402-16:04:42.486(-4)吗? at createUser (password_server.js:980:25) 在createUser(password_server.js:980:25)

Does anyone have any idea what exactly is happening? 有人知道到底发生了什么吗?

The variable ROLES isn't defined in the context of your hook. 变量ROLES不在钩子上下文中定义。 It's either not a global or you're using Meteor 1.3 and you haven't exported it from the file you've defined it in and imported it into the file where you defined your hook. 它不是全局的,或者您正在使用Meteor 1.3,并且尚未从定义它的文件中导出它并将其导入到您定义钩子的文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM