So far I've been looking all over the interwebs and the Meteor docs but nothing has been working for me.
I am creating an account with
Accounts.createUser({
username: username,
email: email,
password: password
});
And I know that is working since {{#if currentUser}}
is working.
However, I am trying to get the current logged-in user's username with something such as
var username = Meteor.userId();
console.log(username);
var username = Meteor.userId().username;
console.log(username);
But neither is working, when I use Meteor.userId()
I just get a random(I'm guessing encrypted) string of numbers and letters, and when I use Meteor.userId().username
it says it's undefined.
All help is welcome and sorry for my possibly terrible grammar, It's very late here!
Meteor.userId()
returns the _id of the user from the Mongo.users collection. That's why it looks like a meaningless string.
You want Meteor.user()
. The docs are your best friend :)
Try with {{currentUser.username}}
I am doing it like this:
User needs to be logged in, else Meteor.user() returns null.
Edit: Also keep in mind Meteor.user() will not be available until the users collection is sinced to the client.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With