Comments (8)
Hi Shkumbini,
I think what's happening is that since you are running this on the client, the call to 'Accounts.createUser' is async so it will immediately return and your id will be undefined (or maybe null). You can verify this by logging the value right before the Roles call.
Move this code to a server-side Meteor method which you call from your #signup click event handler and it should work.
Cheers,
Adrian
Sent from my phone
On Apr 23, 2014, at 11:06 AM, Shkumbini [email protected] wrote:
Hi there
I'm trying to set a sign up form but this error comes in Chrome Inspect when I click Sign Up, here's the code:
Template.signUp.events({
'click #signup': function (e, t) {
e.preventDefault();var users = [ { name: t.find('#fullName').value, email: t.find('#email').value, roles:['admin'] }, { name:"View-Secrets User", email:"[email protected]", roles:[ 'view-secrets' ] } ]; _.each(users, function (user) { var id; id = Accounts.createUser({ email: user.email, password: t.find('#password').value, profile: { name: user.name } }); if (user.roles.length > 0) { // Need _id of existing user record so this call must come // after `Accounts.createUser` or `Accounts.onCreate` Roles.addUsersToRoles(id, user.roles); } });
}
});—
Reply to this email directly or view it on GitHub.
from meteor-roles.
Yeah, I thought so, but how I'm gonna run client side events in server side. At least cannot find the method to run it in server side. Thanks a lot...
from meteor-roles.
It's a meteor thing. You define a meteor method in your server side code that does the new user creation and roles update. Then you call that from the client side event handler.
Meteor.methods(...)
Meteor.call(...)
Typing from phone so can't give real example but meteor docs and examples show how to use meteor methods and calls.
This SO answer may also be helpful:
http://stackoverflow.com/questions/10343656/meteor-how-to-call-a-method-defined-in-meteor-methods
A
Sent from my phone
On Apr 23, 2014, at 5:02 PM, Shkumbini [email protected] wrote:
Yeah, I thought so, but how I'm gonna run client side events in server side. At least cannot find the method to run it in server side. Thanks a lot...
—
Reply to this email directly or view it on GitHub.
from meteor-roles.
I am having the same problem, please help. I don't know what am doing wrong
My code is below.
//collections/users.js
Meteor.methods({
mCreateUser: function (user) {
if(_.isObject(user)) {
if (user.username) {
var id = Accounts.createUser({
username: user.username,
email: user.email,
password: user.password
});
if (user.roles.length > 0) {
// Need _id of existing user record so this call must come
// after `Accounts.createUser` or `Accounts.onCreate`
//[].concat(user);
Roles.addUsersToRoles(id, user.roles);
}
_.extend(user, {id: id});
return user;
}
}
}
});
//views/register.js
var newUserData = {
username: username,
email: email,
password: password,
roles: ['customer']
};
Meteor.call('mCreateUser', newUserData, function (error, result) {
if (error) {
console.log(error);
return;
}
console.log(result);
}
from meteor-roles.
Hi @evandertino,
Please put together a simple reproduction of the issue. (If you'd like help on how to make the reproduction let me know.)
Once its up on Github, post a link here and I'll help debug it.
from meteor-roles.
Hey @alanning,
Yes, I already setup a simple reproduction, of my issue.
You can check it out here
Thank you.
from meteor-roles.
Hi @evandertino,
The error that I see displayed is Chrome in your reproduction is:
Exception while simulating the effect of invoking 'rolesCreateUser'
Error
Error: Missing 'users' param
This is because you are exposing your 'rolesCreateUser' method on both the client and the server so it is attempting to simulate the method call on the client in parallel to executing it on the server.
The one on the client throws that error because on the client the Accounts.createUser call just prior to the Roles.addUsersToRoles call does not immediately add the new user to the client collection. Rather it does it on the server side so there is a delay before that change is propagated back to the client.
So on the client, when the Roles.addUsersToRoles call is called it checks for the user by _id in the local, client-side collection and doesn't find it, thus throwing the error.
To fix this issue, move your rolesCreateUser
meteor method definition to be server-side only. This will prevent the Meteor client from trying to simulate it. You can do that by moving the collections/users.js
file to server/collections/users.js
.
from meteor-roles.
Thank you so much, your explanation was very clear.
from meteor-roles.
Related Issues (20)
- API docs linked to old version of codes HOT 1
- getUsersInRole reactivity? HOT 1
- getScopesForUser is not in documentation HOT 1
- How to run migration script from V1 -> V3 HOT 3
- Exception on subscription: $in needs an array.
- Support new Meteor async API (Meteor 2.8+) HOT 2
- Defaut publication uses only user._id, but no index is created on that field only HOT 2
- cannot add data into role-assignment HOT 3
- Meteor.roleAssignment, error: Property 'roleAssignment' does not exist on type 'typeof Meteor'. HOT 5
- Weird issue with role-assignement.. HOT 2
- Upgrading from 3.4.0 to 3.5.0 introduces 6x node "UnhandledPromiseRejectionWarning: TypeError: Cannot set property 'isCalledFromAsync' of undefined" warnings. HOT 1
- TypeError: Cannot set property 'isCalledFromAsync' of undefined ... HOT 4
- Improve community standards HOT 1
- Add code quality tools HOT 2
- Add selector to Roles.getUsersInRole HOT 2
- forwardMigrate2 tries to drop unset index HOT 1
- Add new function to change scope of existing role assignment HOT 1
- addRolesToParent -> Reset inheritance as unwanted roles may still be connected HOT 1
- Get a list of users with a scope HOT 13
- api docs still show v.3.4.0 in upper right corner HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meteor-roles.