0

In admin part of my Meteor app, I want to call Account.CreateUser(..) for a 'PowerUser' with USERNAME_AND_OPTIONAL_EMAIL (or EMAIL_ONLY) and then sendVerificationEmail, this works great...

Accounts.config(sendVerificationEmail: true);

but next I also want to call Account.CreateUser(..) for a 'LocalUser' with USERNAME_ONLY and not sendVerificationEmail because local user account does not require e-mail.

Accounts.config(sendVerificationEmail: false);

My problem is "Error: Can't set sendVerificationEmail more than once" when I call Accounts.config the second time.

gbdMeteor
  • 123
  • 1
  • 8

1 Answers1

2

I have found that configuring to USERNAME_AND_OPTIONAL_EMAIL is sufficient for both cases:

one-time config on the Client:

Accounts.ui.config({ passwordSignupFields: 'USERNAME_AND_OPTIONAL_EMAIL' });

one-time config on the Server:

Accounts.config({
    sendVerificationEmail: true, 
    forbidClientAccountCreation: true
})

Then code to create a 'LocalUser' provides the username and the initial password

  var newUserId = Accounts.createUser({
        username: username,
        password: 'pw_for_' + username,
        profile: {
          name: name,
          company: company
        }
      }); 

And provide administrator with these values to communicate to the new LocalUser so that they can log in. Since there is no e-mail, no verification email is required to be sent.

Then code to create the PowerUser, provides the email (optional username) and NO password:

   var newUserId = Accounts.createUser({
        email: email,
        profile: {
          name: name,
          company: company
        }
      }); 

and then we send enrollment email so that PowerUser will receive link to set their initial password:

var enroll = Accounts.sendEnrollmentEmail(newUserId);

That's it!

gbdMeteor
  • 123
  • 1
  • 8