【问题标题】:Cannot add email using Accounts package in Meteor无法使用 Meteor 中的 Accounts 包添加电子邮件
【发布时间】:2016-02-16 07:02:15
【问题描述】:

在尝试使用meteor中的一些基本账户方法时,

  • Accounts.addEmail
  • Accounts.setUsername

我总是收到以下错误:

Uncaught TypeError: Accounts.[function] is not a function

这很令人困惑,因为其他 Accounts 方法(例如 Accounts.createUser)按预期工作。其他一些threads 提到这可能与流星过时有关。情况并非如此,因为我运行的是最新版本(1.2.1)。

另外,如果我启动 meteor shell 命令并搜索 Accounts.addEmail 或 Accounts.setUsername,shell 会指出它们确实是函数。

我正在使用的相关包是:

  • 账户密码
  • 账户-ui

【问题讨论】:

  • 您很可能从浏览器/客户端调用这些函数。这些功能仅在服务器端有效。

标签: meteor meteor-accounts accounts


【解决方案1】:

就像 Blaze 在评论中所说,您提到的两种方法都是服务器端的,正如您在 meteor doc 中看到的那样。由于 Meteor 没有附带内置的角色包,它允许您确保这些方法由正确的人根据您的喜好调用。您必须使用Meteor.call('foo') 调用这些方法,同时确保安全或权限。

例如:

Meteor.methods({
    addNewEmail: function(email) {
        'use strict';

        Accounts.addEmail(this.userId, email);
        Accounts.sendVerificationEmail(this.userId, email);
        return true;
    }
});

这段代码确保调用该方法的人会向自己而不是其他人添加电子邮件。您还可以使用alanning:roles 进行一些额外检查。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-25
    • 1970-01-01
    相关资源
    最近更新 更多