I want to create an admin user if no users exist. I tried it on a js file inside the server folder
Meteor.startup(function () {
if(!Meteor.users.find().count()
this way works for me:
var users=[
{email: "dgra@gmail.com", username: "gra", name: "gra", roles:['admin']}
];
_.each(users, function(user){
Accounts.createUser({
email: user.email,
password: "admin",
profile: {username: user.username},
profile: {name: user.name},
roles: user.roles
});
});
After some time, I tested again the above code with meteor 0.6.4 and it worked without problem. Probably was an issue with meteor 0.6.1 or I accidentally solved the problem somewhere in the code.
I've never found any problem on creating a user on Meteor. This is my coffeescript code:
Meteor.startup ->
if Meteor.users.find.count() is 0
options =
email: 'email@example.com'
password: 'pass'
Accounts.createUser(options)
I would suggest a /server/fixtures.js file. In this file, you can add your default user creation as such:
if ( Meteor.users.find().count() === 0 ) {
Accounts.createUser({
username: 'username',
email: 'email',
password: 'asdfasdf',
profile: {
first_name: 'fname',
last_name: 'lname',
company: 'company',
}
});
}