0

I need to use Accounts.setPassword outside of meteor server methods, but on server side. With collections in this case I use Fiber wrapper but it doesn't work with Accounts.setPassword.

Fiber(function(){Accounts.setPassword(msg.user_id, msg.password);}).run();
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Denis
  • 7,127
  • 8
  • 37
  • 58

1 Answers1

0

I just tested it and simple

if (Meteor.isServer) {
  Meteor.startup(function () {
    Accounts.setPassword("Jp2G9TJLHwqagQmMr", "654321")
  });
}

Works just fine on server side. However, if you pass your function in a callback (as an event handler), then don't forget to wrap it into Meteor.bindEnvironment:

something.on('event',
  Meteor.bindEnvironment(function(){
    Accounts.setPassword(msg.user_id, msg.password);
  },
  function (err) {
    console.log('failed to bind env: ', err);
  })
);
imslavko
  • 6,596
  • 2
  • 34
  • 43