Anders Kitson
Anders Kitson

Reputation: 1545

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

Upvotes: 0

Views: 80

Answers (1)

benstr
benstr

Reputation: 652

Try this.

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

Upvotes: 1

Related Questions