访问Meteor JS应用中的用户电子邮件地址

squ*_*ime 17 javascript json username meteor

我正在使用Meteor构建应用程序,需要访问已登录用户的存储电子邮件地址.

我目前正在使用:

var userObj = Meteor.user();
console.log(userObj);
Run Code Online (Sandbox Code Playgroud)

访问用户.但是,我只能访问id.电子邮件地址存储在嵌套对象中,如下所示:

[Object {address="address@gmail.com", verified=false}]
Run Code Online (Sandbox Code Playgroud)

我已经尝试了各种方法来遍历JSON对象,但无法弄清楚如何访问我需要的值.

Dav*_*ave 35

Meteor.user().emails[0].address 适合我.

以下是该文档所说的内容:

默认情况下,服务器会发布用户名,电子邮件和个人资料.有关用户文档中使用的字段的更多信息,请参阅 Meteor.users.

示例用户文档:

{
  _id: "bbca5d6a-2156-41c4-89da-0329e8c99a4f",  // Meteor.userId()
  username: "cool_kid_13", // unique name
  emails: [
    // each email address can only belong to one user.
    { address: "cool@example.com", verified: true },
    { address: "another@different.com", verified: false }
  ],
  createdAt: 1349761684042,
  profile: {
    // The profile is writable by the user by default.
    name: "Joe Schmoe"
  },
  services: {
    facebook: {
      id: "709050", // facebook id
      accessToken: "AAACCgdX7G2...AbV9AZDZD"
    },
    resume: {
      loginTokens: [
        { token: "97e8c205-c7e4-47c9-9bea-8e2ccc0694cd",
          when: 1349761684048 }
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)


Dav*_*ihl 5

您没有指定验证用户的方式.例如,如果您仅使用Google身份验证,则只能在以下位置找到电子邮件地址

Meteor.user().services.google.email
Run Code Online (Sandbox Code Playgroud)

所以,这取决于.