Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
69
rated 0 times [  73] [ 4]  / answers: 1 / hits: 15769  / 12 Years ago, sat, december 22, 2012, 12:00: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();
console.log(userObj);


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 {[email protected], verified=false}]


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


More From » json

 Answers
110

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: [email protected], verified: true },
{ address: [email protected], 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 }
]
}
}
}

[#81265] Thursday, December 20, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ravenl

Total Points: 338
Total Questions: 107
Total Answers: 112

Location: Belize
Member since Mon, Jun 20, 2022
2 Years ago
ravenl questions
Thu, Feb 18, 21, 00:00, 3 Years ago
Tue, Jan 12, 21, 00:00, 3 Years ago
Tue, Mar 17, 20, 00:00, 4 Years ago
;