Access user email address in Meteor JS app
Solution 1
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 }
]
}
}
}
Solution 2
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.
Solution 3
Try this:
Meteor.user().emails[0].address
Regards,
Related videos on Youtube
squeezemylime
Startup guy. Design aficionado. Mobile innovator. I work as a UX Consultant via Optimino (optimino.com). My current focus is on bringing innovative products to market as quickly as possible and with few obstacles, working with agile teams across the globe to develop solutions for clients in the Internet and Mobile industry. I am results-driven and imaginative, always seeking new and better ways of getting things done.
Updated on August 30, 2022Comments
-
squeezemylime over 1 year
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 {address="[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.
-
Rahul over 11 yearsIf his console has the object he posted in the OP, then he's using accounts-passwords or something similar, he just hasn't figured out how to access the properties correctly.