How to create a default user on meteor?

前端 未结 4 765
感动是毒
感动是毒 2021-02-19 03:39

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()         


        
4条回答
  •  暖寄归人
    2021-02-19 04:09

    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
        });
    });
    

提交回复
热议问题