How to create a default user on meteor?

前端 未结 4 781
感动是毒
感动是毒 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:19

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

提交回复
热议问题