Closed trajano closed 8 years ago
I found a bit of a workaround, but seems to work. The idea is to do the job on the server which is what is done on #35 to begin with. I used a the Meteor.call
on the client to call a Meteor.methods
on the server. Keeping it open for now in case there is a correct way of doing it on the client side that I am missing. (Apologies I just started learning Meteor last week while I was stuck at home with a cold).
Meteor.methods({ /** * This will create the initial admin user. This will only work if one does not presently exist, if one does exist it will throw an error. * @param email * @param password */ createInitialAdminUser: function (email, password) { if (Roles.getUsersInRole('admin', null, {reactive: false, limit: 1}).count() != 0) { throw new Meteor.Error("An existing admin user is already present"); } var userId = Accounts.createUser({email: email, password: password}); Roles.addUsersToRoles(userId, ['admin']); }, /** * * @returns {boolean} true if there is at least one admin user */ hasAdminUser: function() { var c = Roles.getUsersInRole('admin', null, {reactive: false, limit: 1}).count(); return c != 0; } });
Yes, in fact the best way is to add do all changes inside Meteor methods.
Similar to #35 but I want to do it from the client side. I tried to follow the examples on #35 but it didn't work. This is the closest that I can make it run but it fails in the end with an
update failed: Access denied
.The approach I was taking was to do it via callback event since that is the only time I can be sure that the user was created or had an explicit error. I have verified that there are values in the console log.
In fact for a short while the user does have that role, but the update gets rolled back due to update failed.