在 Meteor JS 应用程序中访问用户电子邮件地址 [英] Access user email address in Meteor JS app

查看:13
本文介绍了在 Meteor JS 应用程序中访问用户电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am building an app using Meteor and need to access the stored email address of a logged-in user.

我目前正在使用:

var userObj = Meteor.user();
console.log(userObj);

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

to access the user. However, I am only able to access the id. The email address is stored in a nested object that looks like this:

[Object {address="address@gmail.com", verified=false}]

我尝试了各种方法来遍历 JSON 对象,但不知道如何访问我需要的值.

I have tried various ways to traverse the JSON object but can't figure out how to access the value I need.

推荐答案

Meteor.user().emails[0].address 对我有用.

文档内容如下:

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

By default the server publishes username, emails, and profile. See Meteor.users for more on the fields used in user documents.

示例用户文档:

{
  _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 }
      ]
    }
  }
}

这篇关于在 Meteor JS 应用程序中访问用户电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆