【问题标题】:Access user email address in Meteor JS app在 Meteor JS 应用程序中访问用户电子邮件地址
【发布时间】:2012-12-09 20:47:37
【问题描述】:

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

我目前正在使用:

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

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

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

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

【问题讨论】:

    标签: javascript json meteor


    【解决方案1】:

    试试这个:

    Meteor.user().emails[0].address

    问候,

    【讨论】:

      【解决方案2】:

      您没有指定如何对用户进行身份验证。例如,如果您仅使用 Google 身份验证,则电子邮件地址只能在

      中找到
      Meteor.user().services.google.email
      

      所以,这取决于。

      【讨论】:

      • 如果他的控制台有他在 OP 中发布的对象,那么他正在使用帐户密码或类似的东西,他只是还没弄清楚如何正确访问这些属性。
      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-21
        • 2016-12-17
        • 2017-05-11
        相关资源
        最近更新 更多