【问题标题】:How to prevent Meteor's accounts-base from auto-publishing the email of the current user?如何防止 Meteor 的帐户库自动发布当前用户的电子邮件?
【发布时间】:2021-03-23 12:08:32
【问题描述】:

根据帐户包上的Meteor's documentation

默认情况下,当前用户的用户名、电子邮件和个人资料都会发布到客户端。

是否可以阻止 Meteor 自动发布这些字段?我知道这仅适用于已登录的用户,但该用户可以在公共场所散步或在线。

这种代码结构似乎在 accounts_server.js 中定义(搜索 autopublish 和 email - 第 37 和 696 行)。

【问题讨论】:

    标签: meteor meteor-accounts meteor-publications


    【解决方案1】:

    最直接的方法是修改Accounts._defaultPublishFields.projection 的值并删除 emails 键。在保持其他值的同时做到这一点的一种简单方法是使用 rest 和 spread 的组合,如下所示:

    import { Accounts } from 'meteor/accounts-base';
    
    const { emails, ...fields } = Accounts._defaultPublishFields.projection;
    Accounts._defaultPublishFields.projection = { ...fields };
    

    只要确保它在服务器上运行就可以了。

    【讨论】:

      猜你喜欢
      • 2014-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-27
      • 2019-02-13
      • 2015-09-29
      • 2021-05-29
      • 1970-01-01
      相关资源
      最近更新 更多