簡體   English   中英

在 Meteor JS 應用程序中訪問用戶電子郵件地址

[英]Access user email address in Meteor JS app

我正在使用 Meteor 構建應用程序,並且需要訪問已登錄用戶的存儲電子郵件地址。

我目前正在使用:

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

訪問用戶。 但是,我只能訪問該 ID。 電子郵件地址存儲在如下所示的嵌套對象中:

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

我嘗試了各種方法來遍歷 JSON 對象,但無法弄清楚如何訪問我需要的值。

Meteor.user().emails[0].address對我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 }
      ]
    }
  }
}

您沒有指定如何對用戶進行身份驗證。 例如,如果您僅使用 Google 身份驗證,則只能在以下位置找到電子郵件地址

Meteor.user().services.google.email

所以,這取決於。

試試這個:

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

問候,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM