Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create users server side in Meteor?

Tags:

meteor

In the new Meteor auth branch how can I create users server side?

I see how to create them client side with the call to

[Client] Meteor.createUser(options, extra, callback)

But suppose I want to create a Meteor user collection record on startup?

For example, the Administrator account during startup/bootstrapping for an application?

Thanks Steeve

like image 732
Steeve Cannon Avatar asked Jul 24 '12 11:07

Steeve Cannon


People also ask

What is the meteor user () function for?

The Meteor Accounts system builds on top of the userId support in publish and methods . The core packages add the concept of user documents stored in the database, and additional packages add secure password authentication, integration with third party login services, and a pre-built user interface.

Which of the following user accounts packages are provided by the meteor developer group?

Here's a complete list of login providers for which Meteor actively maintains core packages: Facebook with accounts-facebook. Google with accounts-google. GitHub with accounts-github.

How do I call Meteor method?

Meteor methods are functions that are written on the server side, but can be called from the client side. On the server side, we will create two simple methods. The first one will add 5 to our argument, while the second one will add 10.


1 Answers

On newer versions of meteor use

  Accounts.createUser({
                            username: username,
                            email : email,
                            password : password,
                            profile  : {
                                //publicly visible fields like firstname goes here
                            }

    });

note: the password hash is generated automatically

On older versions of meteor use:

1 - NB: DO YOU HAVE THE REQUIRED PACKAGES INSTALLED ?

  • mrt add accounts-base
  • mrt add accounts-password

On some versions of meteor you cannot call SRP password salt generator as Steeve suggested, so try this:

2 - do Meteor.users.insert( )

e.g.

 var newUserId = 
 Meteor.users.insert({
         emails: ['[email protected]'],
         profile  : { fullname : 'peter' }
 });

note: a user must have EITHER a username or an email address. I used email in this example.

3 - Finally set the password for the newly created account.

      Accounts.setPassword(newUserId, 'newPassword');
      
like image 78
user3462143 Avatar answered Sep 20 '22 14:09

user3462143