Upon submit of a post, the current user does not seem to be recognised and username appears as blank. The submit html has {{author}} to display the user who wrote the post.
Heres the results when I type the following in the console:
1)user.username
=> result user is undefined.
2)Meteor.users.find();
=> LocalCollection.Cursor {collection: LocalCollection, sorter: null, _selectorId: undefined, matcher: Minimongo.Matcher, skip: undefined…}
3) Meteor.users.findOne();
=> Object {_id: "P3ocCTTdvi2o3JApf", profile: Object}
compared to the working version (Note my version is missing username)
=> Object {_id: "XHXPebzjg5LM5tNAu", profile: Object, username: "Bruno"}
In post.js collection (in the lib folder - shared with both client and server), I have:
Meteor.methods({
postInsert: function(postAttributes) {
check(this.userId, String); //check(Meteor.userId(), String);
check(postAttributes, {
title: String,
message: String
});
var user = Meteor.user();
var post = _.extend(postAttributes, {
userId: user._id,
author: user.username
});
var postId = Posts.insert(post);
return {_id: postId};
},
There are also no other references to author in the Discover Meteor tutorial, and it worked. However mine doesnt work. This problem seems to have started after I added UserAccounts package. Or perhaps a folder location issue?
Update [11 May 2015]
I realised that when using the original ui-accounts that came with Meteor, it has the username field because the sign up link that came with {{> login}} uses username + password. Theres no email address involved.
UserAccounts on the other hand doesnt have this username field. Its either email/pw or social login. So perhaps someone guide me on how to have username (either as separate field or derived from email) from email/pw and social network button login/signin as a start? Then Ill try to fiddle from there.
code for UserAccounts
router.js
//Iron router plugin to ensure user is signed in
AccountsTemplates.configureRoute('ensureSignedIn', {
template: 'atTemplate', //template shown if user is not signed in
layoutTemplate: 'atLayout' //template for login, registration, etc
});
Router.plugin('ensureSignedIn', { //Don't require user logged in for these routes
except: ['login', 'register'] //can use only: too
});
AccountsTemplates.configureRoute('signIn', { //login
name: 'login',
path: '/login',
template: 'atTemplate',
layoutTemplate: 'atLayout',
redirect: '/'
});
AccountsTemplates.configureRoute('signUp', { //registration
name: 'register',
path: '/register',
template: 'atTemplate',
layoutTemplate: 'atLayout',
redirect: '/'
});
and under config.js (server side)
{{expr}}directly in the console, the curly braces fail object literal interpretation so become code blocks instead. Meaning it's almost exactly the same as just doingexpr. i.e. theauthoryou tried to access in the Console was using vanilla JavaScript and not meteor. - Paul S.{{expr}}. As for code, as the devtool is not throwing up errors, Im not sure which part of the code to consider pasting. I did a search on all parts that had{{author}}oruserand hence pasted only the part within collections. Would you have suggestions on where to start looking or other tools to use etc? - Thinkerer