SOLVED - TypeError: Accounts.createUser is not a function

I am creating one app and getting the following error:

TypeError: Accounts.createUser is not a function

Here is my Code:

Template.register.events({
    'submit form': function(event){
	event.preventDefault();
	var email = $('[name=email]').val();
	var password = $('[name=password]').val();
		var fname = $('[name=fname]').val();
		var lname = $('[name=lname]').val();

	Accounts.createUser({
	    email: email,
	    password: password,
			profile: {
			fname: fname,
			lname: lname,
			IsActive: 0
			}

	});
	Router.go('home');
    }
});

I am using the : accounts-password package

I am also using the MONGO_URL (MONGO_URL=mongodb://localhost:27017/MYDB)

I have tried : meteor reset
also recreated the app by : meteor create myapp

I can login thru the already created user, Previously it was not giving any issues and I created one User, but now it is giving this issue, What should I do?

Thanks and Best Regards,
Manu

What packages/versions have you got (meteor list)?

1 Like

you need add package accounts-password

1 Like

Hi All,

Here is what I was doing wrong :

I was using a collection having a name as Accounts, see below :

OLD CODE

Accounts = new Meteor.Collection('accounts');

Subscriptions :

Meteor.publish('Accounts', function(){
return Accounts.find();
});

Helpers:

Template.account_screen_account_view.helpers({

FetchAccountViewData: function () {
var editid = Router.current().params._id;
return CustomerAccounts.findOne({_id:editid});
}

});

It was conflicting with the following code:

  Accounts.createUser({
    email: email,
    password: password,
	profile: {
	fname: fname,
	lname: lname,
	IsActive: 0
	}

});

NEW CODE (CHANGED)

CustomerAccounts = new Meteor.Collection('customeraccounts');

Meteor.publish('CustomerAccounts', function(){
return CustomerAccounts.find();
});


Template.account_screen_account_view.helpers({

FetchAccountViewData: function () {
var editid = Router.current().params._id;
return CustomerAccounts.findOne({_id:editid});
}

});

Now the issue is resolved. Sometimes we forget to look into these things, I am happy to share my experience as if you use Meteor Accounts, then you need to change the name of your own collections and functions as they can conflict and create these type of issues. :smile:

1 Like

I was working in a team project, and didn’t know that one of the members created a collection called “Accounts”. I’ve spent 2 hours to find the error and read your response and problem solved. Thank you~~~!!!

:slight_smile: Good to know it solved your issue