When trying to use some of the basic accounts methods in meteor,
I always get the following error:
Uncaught TypeError: Accounts.[function] is not a function
This is confusing since other Accounts methods such as Accounts.createUser work as expected. Some other threads mentioned that this might have to do with meteor being out of date. This is not the case as I am running the latest version (1.2.1).
Also, if I start up the meteor shell
command and search for either Accounts.addEmail or Accounts.setUsername, the shell states that they are indeed functions.
The relevant packages I am using are:
Like Blaze said in comment, both methods you mentioned are server-side only as you can see in meteor doc. As Meteor does not ship with a built-in roles package, it allows you to ensure those methods are called by the right person according to your liking. You'll have to use Meteor.call('foo')
to call these methods while ensuring security or permissions.
For example:
Meteor.methods({
addNewEmail: function(email) {
'use strict';
Accounts.addEmail(this.userId, email);
Accounts.sendVerificationEmail(this.userId, email);
return true;
}
});
This piece of code makes sure the guy calling the method will add an email to himself and not somebody else. You could also use some extra checks by using alanning:roles
.