Yes, you can use multiple params. You don’t need to use the :userName param in this case unless you need to specify additional data to use. Instead it can be a dynamic part of the URL.
Edit: The :userName param would be used to prevent the post showing under a username the post does not belong to.
This will conflict with other routes so you could either do /:userName/profile, /p/:userName, /profile/:userName or try defining that route after all your other routes (not sure if that will work though)
I’m assuming I need to make sure a collection is created, with subscription and published enabled? In addition, on user creation, create one profile per user?
Yes you will need to publish and subscribe to the user data if you don’t have autopublish on.
Also when you call your profileInsert method you are not passing any data.
And the onCreateUser function should return a user document as stated in the docs. In your profileInsert method you will not have access to Meteor.user() since it will not be in the database yet. So you could set a random id in your create user function. Example of how I would do it:
Well you will have to handle image uploads then, but just put them in the profile object and you will have access to them.
As stated above though it’s much easier to just store the users profile directly in the user document, since you will have an extra query every time.
e.g like this
Accounts.onCreateUser(function(options, user) {
// anything you want to change about user or profile here
if (options.profile)
user.profile = options.profile;
return user;
});
I20150613-06:11:22.490(-7)? Exception while invoking method ‘ATCreateUserServer’ TypeError: Cannot set property 'id’ of null
I20150613-06:11:22.490(-7)? at Meteor.methods.profileInsert..extend.userId (app/lib/collections/profiles.js:6:14)
``
Accounts.onCreateUser(function() {
var user = Meteor.user();
user._id = Random.id(); //line 6
if(options.profile)
Meteor.call('profileInsert', options.profile, user);
return user;
});
So I think line 6 is giving me an error. Why would I want to assign a Random id to the a new user? Doesn’t my accounts package already do that for me?
Oh and I added the user variable because another error was saying it was not defined.
ReferenceError: user is not defined
I20150613-06:29:37.055(-7)? at [object Object].Meteor.methods.profileInsert (app/lib/collections/profiles.js:17:19)
Something going on with line 17. Which I don’t understand because that is the same code I use when I need a user to create a new post and add it to the database.
You are not taking in the user in your profileInsert method and in onCreateUser you should take in options and user. Look at the code I provided again.
var user = Meteor.user() will not work since there is no user yet. onCreateUser gets called BEFORE the user is put into the database
this seems as new neverending thread, everything he copy without reading any docs and understanding how it works or how passing arguments in functions/events work…
and with Iron router subject, when working with methods and creating users atm
W20150613-06:53:37.625(-7)? (STDERR) Error: Can only call onCreateUser once
W20150613-06:53:37.626(-7)? (STDERR) at Object.Accounts.onCreateUser (packages/accounts- base/accounts_server.js:963:1)