Access user email address in Meteor JS app

后端 未结 3 1944
我寻月下人不归
我寻月下人不归 2020-12-30 04:00

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

I am currently using:

var userObj = Meteor.user();         


        
相关标签:
3条回答
  • 2020-12-30 04:31

    Meteor.user().emails[0].address works for me.

    Here's what the doc says:

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

    Example user document:

    {
      _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 }
          ]
        }
      }
    }
    
    0 讨论(0)
  • 2020-12-30 04:32

    Try this:

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

    Regards,

    0 讨论(0)
  • 2020-12-30 04:51

    You don't specify how you are authenticating users. For example, if you were using Google authentication only, the email address would be found only in

    Meteor.user().services.google.email
    

    So, it depends.

    0 讨论(0)
提交回复
热议问题