Reputation: 33
The default setting in Meteor does not allow account creation from the Client, which makes sense for security purposes in many applications, but I am building a blog and need to allow users to create an account so they can leave comments.
The typical response on github, stackoverflow, and various tutorials seems to suggest adding the following code to your files, anywhere outside of the client/server conditionals, so that it can run on both client AND server:
Accounts.config({
forbidClientAccountCreation: false
});
Seems simple enough. I entered this bit of code in a file (configure.js) in my lib folder, but the following error message appears in the Terminal:
W20150925-19:52:17.568(9)? (STDERR) /Users/Eric/.meteor/packages/meteor-tool/.1.1.4.2l3p0l++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
W20150925-19:52:17.568(9)? (STDERR) throw(ex);
W20150925-19:52:17.568(9)? (STDERR) ^
W20150925-19:52:17.627(9)? (STDERR) Error: Can't set `forbidClientAccountCreation` more than once
W20150925-19:52:17.627(9)? (STDERR) at packages/accounts-base/accounts_common.js:95:1
W20150925-19:52:17.627(9)? (STDERR) at Array.forEach (native)
W20150925-19:52:17.627(9)? (STDERR) at Function._.each._.forEach (packages/underscore/underscore.js:105:1)
W20150925-19:52:17.628(9)? (STDERR) at Object.Accounts.config (packages/accounts-base/accounts_common.js:92:1)
W20150925-19:52:17.628(9)? (STDERR) at app/lib/configure.js:1:45
W20150925-19:52:17.628(9)? (STDERR) at app/lib/configure.js:5:3
W20150925-19:52:17.628(9)? (STDERR) at /Users/Eric/pilgrim/.meteor/local/build/programs/server/boot.js:222:10
W20150925-19:52:17.628(9)? (STDERR) at Array.forEach (native)
W20150925-19:52:17.628(9)? (STDERR) at Function._.each._.forEach (/Users/Eric/.meteor/packages/meteor-tool/.1.1.4.2l3p0l++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20150925-19:52:17.628(9)? (STDERR) at /Users/Eric/pilgrim/.meteor/local/build/programs/server/boot.js:117:5
=> Exited with code: 8
=> Your application is crashing. Waiting for file change.
The line "Can't set forbidClientAccountCreation
more than once" seems to imply that the problem is stemming from multiple packages reasserting this same code in some manner.
I have a few packages such as accounts-ui, accounts-password, useraccounts:core, and useraccounts:foundation, but it appears that Meteor gets overwhelmed with conflicting signals (others have complained of a conflict with useraccounts:bootstrap as well.) I'm not certain if any of these are a direct source of conflict in my code, and other developers suggest removing any conflicting packages, but that seems like a poor solution. The packages were added for a reason. There should be a way to definitively set this variable without issue.
I can't seem to find a reasonable solution to this. Thoughts?
Upvotes: 3
Views: 1063
Reputation: 516
I am guessing that you have installed a package like useraccounts:bootstrap
or useraccounts:materialize
.
You can change this setting by changing the value of Accounts._options.forbidClientAccountCreation
to true.
Upvotes: 0
Reputation: 757
You can't set it to false while using the useraccounts:core
package because that package sets it to true. The useraccounts
suite provides a UI that should allow users to create accounts by default. You can't use the UI provided by accounts-ui
to create your users (nor use Accounts.createUser()
on the client) while using the useraccounts
suite.
Upvotes: 3
Reputation: 3200
Meteor does allow account creation from the client.
It's best to think of how you have set up your project in terms of the packages you have added and/or removed and which block (server/client) is the code written.
Understanding which packages you have added/removed is the underlying factor as to how users can be created either from the client, and/or server.
Which package are you using to create a user?
The below is a simple example of creating a user from the client using the accounts-password
package. The credentials a user provides here is an email address and password. Note, there are external packages in which to create users as well.
First:
meteor remove insecure
meteor add accounts-password
HTML:
<body>
{{> join}}
</body>
<template name="join">
<input type="email" id="email">
<input type="password" id="password" placeholder="6 charactors minimum">
<button class="submit"></button>
</template>
JS:
Template.join.events({
'click .submit': function(e, template) {
var email = template.find('#email').value;
var password = template.find('#password').value;
Accounts.createUser({
email: email,
password: password
},
function(error) {
if (error) {
console.log(error);
}
else {
console.log("account created");
}
});
}
});
Open the mongo shell and type db.users.find()
and you will see the user that was created.
In future, it's best to pose a question providing further details that enable SO community to reproduce the code/problem and therefore, a resolution.
Upvotes: 1