简体   繁体   English

TypeError:Meteor.user(...)。services未定义

[英]TypeError: Meteor.user(…).services is undefined

I'm trying to get a Meteor user's Facebook ID (who is signed in through Facebook). 我正在尝试获取Meteor用户的Facebook ID(通过Facebook登录)。 The following line is giving me trouble: 以下行给我带来了麻烦:

var userID = Meteor.user().services.facebook.id;

In the console it says 在控制台上说

TypeError: Meteor.user(...).services is undefined

From my understanding this is because the user().services hasn't been initialized yet. 据我了解,这是因为user()。services尚未初始化。 I wrapped the code in if(Meteor.user()) to confirm the user has been initialized. 我将代码包装在if(Meteor.user())以确认用户已被初始化。 The code is executed when a button is pressed, so it definitely has enough time to start. 该代码在按下按钮时执行,因此肯定有足够的时间启动。 This started happening when I removed autopublish (although that could be unrelated). 当我删除自动发布时,这种情况就开始发生(尽管可能无关)。 Is there anything additional I need to do to make it work without autopublish? 我需要做些其他事情才能使其在没有自动发布的情况下工作吗?

Solved it with the following: 解决了以下问题:

Meteor.publish("getUserData", function () {
    return Meteor.users.find({_id: this.userId});
});

and subscribing to that. 并订阅。 Once that subscription is filled all of the Meteor.user.services data is available. 填写该订阅后,所有Meteor.user.services数据都将可用。

The services key is not included by default in the user's document on the client because it contains security details. 默认情况下, 服务密钥不包含在客户端的用户文档中,因为它包含安全性详细信息。 You could fetch it via a method call or publish it specifically from the server and subscribe to it. 您可以通过方法调用来获取它,也可以从服务器专门发布它并进行订阅。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM