MeteorJS how to add users from the command line

How can I add users to an application outside of the application itself? I do not want users to be able to create accounts inside the application. Can I create several user names and passwords from the command line and then provide them to several users for testing the application?

Let me know if you need more information or if I am unclear. Thank you so much for your time.

+5
source share
2 answers

Suppose you have the accounts-password package installed. (You probably have been doing this since you already have logged in.)

You can run meteor shell and type

Accounts.createUser({username: 'john', password: '12345'})

This will take care of all bcrypting for you. You should also be able to script.

Relevant documentation with additional parameters here .

+7
source

You can add users from the command line, but it is not so simple.

Essentially, you need to run something like mongo. For simplicity, I'm not going to add bcrypt code to create passwords.

Instead, you can use a shared meteor password (default). To do this, create the meteor application, add accounts-password and create a user account. Use the value of services.password.bcrypt for all users). When you create a user account, this bcrypt represents the generated user password.

Then you can create a default script:

 var user = { "createdAt": new Date(), "emails": [ ], "username": "<username>", "profile": { "name": "<Name>" }, "services": { "password": { "bcrypt": "$2a$10$eUVSifclpbABCDEFGHIJKLmnopqr12323112ABBBCEDOINg2A7q0e" }, "resume": { "loginTokens": [ ] } } } db.users.add(user); 

Then you can run this script (be sure to replace the values ​​with and.) _Id if you can with a random string. This way mongodb will generate _id as an ObjectID .

Then you can run this script (if you named it myjsfile.js) from the command line (if mongo is on local port 3001):

 mongo localhost:3001/meteor myjsfile.js 
0
source

All Articles