【问题标题】:Meteor accounts password: TypeError: Accounts.setPassword is not a functionMeteor 帐户密码:TypeError:Accounts.setPassword 不是函数
【发布时间】:2019-01-21 13:24:46
【问题描述】:

我正在使用: 流星版本 1.8, 账户密码@1.5.1

调用时:

  Meteor.methods({
    setPassword(newPassword, userId) {
      check(userId, String);
      check(newPassword, String);
      if(Meteor.user().isAdmin){
        Accounts.setPassword(userId, newPassword);
      }
    },
  });

通过

Meteor.call('setPassword', password, this.userId);

我收到此错误: Exception while simulating the effect of invoking 'setPassword' TypeError: Accounts.setPassword is not a function 但是密码仍然设置...

【问题讨论】:

  • 您的方法是否在“服务器”文件夹中?如果不是,我认为 setPassword 应该在服务器段内,即 'if (Meteor.isServer) {..//your setPassword method}'

标签: meteor meteor-accounts


【解决方案1】:

Meteor 方法可以在服务器端和客户端(see here)上运行。这里的错误来自客户端:simulating the effect 表示客户端正在尝试计算对服务器查询的乐观答案。

Accounts 对象在客户端和服务器端都可用,但我敢打赌,出于安全原因,Accounts.setPassword 函数仅在服务器中可用。

为避免该错误,您可以:将流星方法定义放在仅服务器文件夹see here(如在此文件中app_code/imports/api/accounts/server/methods.js),或使用if(Meteor.isServer) see here 包装它:

if(Meteor.isServer){
    Meteor.methods({
        setPassword(newPassword, userId) {
            check(userId, String);
            check(newPassword, String);
            if(Meteor.user().isAdmin){
                Accounts.setPassword(userId, newPassword);
            }
        },
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-03
    • 2015-01-04
    • 1970-01-01
    • 2018-01-01
    • 2017-12-24
    • 2016-12-20
    • 2015-03-21
    • 2014-03-09
    相关资源
    最近更新 更多