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()) {
var options = {
username: 'admin',
password: 'default-password',
email: '[email protected]'
};
Accounts.createUser(options);
}
});
This is the error that meteor show on the console
Error
at app/packages/livedata/livedata_common.js:143:26
at /Users/camilo/Documents/Proyectos/IM/interno/.meteor/local/build/server/server.js:282:7
at Array.forEach (native)
at Function._.each._.forEach (/Users/camilo/.meteorite/meteors/meteor/meteor/0ffea1c4c308ed24906984f99b13b8fca5a0956c/dev_bundle/lib/node_modules/underscore/underscore.js:79:11)
at run (/Users/camilo/Documents/Proyectos/IM/interno/.meteor/local/build/server/server.js:227:7)
=> Exited with code: 1
I'm doing something wrong or this is a meteor bug?
I'm using meteor 0.6.1 and node.js 0.9.9
userId() import { Meteor } from 'meteor/meteor' (accounts-base/accounts_common.js, line 410) Get the current user id, or null if no user is logged in.
`accounts-base` This package is the core of Meteor's developer-facing user accounts functionality.
Meteor is a full-stack JavaScript platform for developing modern web and mobile applications. Meteor includes a key set of technologies for building connected-client reactive applications, a build tool, and a curated set of packages from the Node. js and general JavaScript community.
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',
}
});
}
this way works for me:
var users=[
{email: "[email protected]", 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
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With