【问题标题】:Meteor.user() doesn't work in ChromeMeteor.user() 在 Chrome 中不起作用
【发布时间】:2017-12-12 15:14:53
【问题描述】:

我正在尝试console.log(Meteor.user().profile.group):但它会导致以下错误:

未捕获的类型错误:无法读取未定义的属性“配置文件”

单独使用Meteor.user() 会返回未定义。

这里是 Mongo 的用户详细信息:

{
        "_id" : "ccZztbFqw2MpgTsjX",
        "createdAt" : ISODate("2017-12-12T15:11:23.645Z"),
        "services" : {
                "password" : {
                        "bcrypt" : "$2a$10$lsYo7wjhA77.8TmNYeMTQ.u3jZzJSiIxsJrMRkjOPINHuLhBOENqm"
                }
        },
        "emails" : [
                {
                        "address" : "111@211.com",
                        "verified" : false
                }
        ],
        "profile" : {
                "name" : "11111",
                "createdAt" : ISODate("2017-12-12T15:11:23.558Z"),
                "updatedAt" : ISODate("2017-12-12T15:11:23.558Z"),
                "group" : "user"
        }
}

为什么 Meteor.user() 在 Chrome 中不起作用?

注意:Meteor.user().profile.group 使用 Microsoft Edge 浏览器将组打印到控制台

【问题讨论】:

  • 它在 Chrome 中工作,只需几毫秒即可加载到客户端。这个问题老是出现。
  • @MichelFloyd 你的权利,我把它放在一个按钮内,可以成功打印组。延迟执行的最佳做法是什么?
  • 取决于你使用的是 Blaze 还是 React。

标签: google-chrome meteor meteor-accounts


【解决方案1】:

可以,但是从服务器下载用户文档需要一段时间。

第一次在浏览器中加载应用时,Meteor.user() 可以是未定义的。

您的用例是什么?如果要访问模板中的当前用户,可以使用currentUser helper:

{{#if currentUser}}
    {{currentUser.profile.group}}
{{/if}}

如果您从 Chrome 开发者控制台调用 Meteor.user(),您还可以查看其中的内容。

【讨论】:

    【解决方案2】:

    默认情况下,Meteor 不会公开用户集合(为了您自己的利益),如果您想控制公开的内容和不公开的内容,而不是简单地为“userData”添加发布功能。

    【讨论】:

    猜你喜欢
    • 2014-09-02
    • 2013-04-18
    • 2011-12-11
    • 2013-07-25
    • 2016-01-26
    • 2013-03-22
    • 2013-06-06
    • 2011-03-06
    • 2013-04-04
    相关资源
    最近更新 更多