Search code examples
meteoruser-accounts

How would I use Accounts.createUser in Meteor once, at first load, and then persist


I have thought of somehow using session, but that doesn't make much sense to me with a user that I always want to exist, and not be created over and over.

My issue is after a page refresh I get an error saying user already exists, I would like to know how to create a permanent user once.

This is in my server code.

Accounts.createUser({
    username: "admin",
    password: "password"
});

Solution

  • Try this.

    Meteor.startup(function () {
      if (Meteor.users.find().count() === 0) {
        Accounts.createUser({
          username: 'admin',
          email: 'admin@admin.com',
          password: 'password'
        });
        console.log('created user');
      }
    });