0

I'm trying to use my own mongo database which is created in mlab in auth0 for user management. Here is the template they provided.

function create (user, callback) {
  mongo('mongodb://user:pass@mymongoserver.com/my-db', function (db) {
    var users = db.collection('users');

    users.findOne({ email: user.email }, function (err, withSameMail) {

      if (err) return callback(err);
      if (withSameMail) return callback(new Error('the user already exists'));

      bcrypt.hashSync(user.password, 10, function (err, hash) {
        if (err) { return callback(err); }
        user.password = hash;
        users.insert(user, function (err, inserted) {
          if (err) return callback(err);
          callback(null);
        });
      });
    });
  });
}

After changing connection URI, I tried to "create" a user by providing email and password with the script. I see the following error:

[SandboxTimeoutError] Script execution did not complete within 20 seconds. Are you calling the callback function?

I followed the Debug Script they provided. Here is the log:

$ wt logs -p "myservice-eu-logs"
[12:35:27.137Z]  INFO wt: connected to streaming logs (container=myservice)
[12:35:29.993Z]  INFO wt: new webtask request 1478435731301.992259
[12:35:30.047Z]  INFO wt: { [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
[12:35:30.047Z]  INFO wt: js-bson: Failed to load c++ bson extension, using pure JS version
[12:36:05.080Z]  INFO wt: finished webtask request 1478435731301.992259 with HTTP 500 in 35096ms

Any suggestions?

  • looks like your missing some external file/module? – mike510a Nov 06 '16 at 13:33
  • A similar issue is posted [here](http://stackoverflow.com/questions/28651028/cannot-find-module-build-release-bson-code-module-not-found-js-bson) for Node. However, I don't have any idea where I can access `bson` variable in Auth0. – Murali Krishna Regandla Nov 06 '16 at 14:03

1 Answers1

1

Actually, bcrypt.hashSync is a synchronous method, so the callback function is never called and the script times out.

Either use:

var hashedPwd = bcrypt.hashSync(user.password);

or

bcrypt.hash(user.password,10,function(....);

Eugenio Pace
  • 14,094
  • 1
  • 34
  • 43