Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MeteorJS how to add users from command prompt

How can I add users to my app outside of the deployed app itself? I don't want to allow users the ability to create accounts inside the app. Can I create some usernames and passwords from the command line and then give those to a few users to test the application?

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

like image 883
user95227 Avatar asked May 28 '15 20:05

user95227


2 Answers

Granted that you have theaccounts-password package installed. (You probably do since you already have login set up.)

You can launch meteor shell and enter

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

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

The relevant documentation with more option parameters is here.

like image 132
oivvio Avatar answered Oct 06 '22 19:10

oivvio


You can add users from the command prompt but its not that easy.

Essentially you need to run something like this from mongo. For the sake of simplicity I'm not going to add in bcrypt code to make passwords.

Instead you can use a generic meteor password (default). For this create a meteor app, add in accounts-password and create a user account. Use the services.password.bcrypt value for all users). When you create a user account this bcrypt has represents the created user's 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 and values. Also the _id if you can with a random string. This way mongodb will generate the _id as an ObjectID.

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

mongo localhost:3001/meteor myjsfile.js
like image 33
Tarang Avatar answered Oct 06 '22 21:10

Tarang