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?
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.
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.
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.
Related
I'm trying to implement the accounts-ui in a mobile angular-meteor app. I have all the dependencies installed, and I'm trying to setup the Accounts.ui.config with the following code:
import { Accounts } from 'meteor/accounts-base';
Accounts.ui.config({
passwordSignupFields: 'USERNAME_AND_EMAIL'
});
But when I try to run the app, I get the following error:
TypeError: Cannot read property 'config' of undefined
at meteorInstall.server.auth.js (server/auth.js:4:1)
at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:153:1)
at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:82:1)
at server/publications.js:124:1
at /home/ubuntu/workspace/musiker/.meteor/local/build/programs/server/boot.js:297:10
at Array.forEach (native)
at Function._.each._.forEach (/home/ubuntu/.meteor/packages/meteor- tool/.1.4.0.hylsrj++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
at /home/ubuntu/workspace/musiker/.meteor/local/build/programs/server/boot.js:133:5
I thought maybe I need to import accounts-ui for the page, but the docs clearly show importing the account-base. I also tried importing the accouns-ui and I still got the same error.
Thank!
-Erick
Add accounts package before using this.
Use this command in the project root to add the package
meteor add accounts-ui accounts-password
This should make your code work.
You need to add the config on client side code :
import { Accounts } from 'meteor/accounts-base';
Accounts.ui.config({
passwordSignupFields: 'USERNAME_ONLY',
});
Have a look here for more details.
It looks like you are trying to execute Accounts.ui.config on the server but this function is only available on the client.
It is Accounts.config.
Accounts.config({
passwordSignupFields: 'USERNAME_AND_EMAIL'
});
I have the same error.
First I put the JS into lib/startup/accounts-config.js or lib/accounts-config.js ,it still has error.
But it becomes effective when I put the JS into imports/startup/accounts-config.js. I don't know the reason.
My app works perfectly fine without a router. I'm using the nathantreid:css-modules package, which allows modular css for your react components. Within my imports/ui/Navbar directory, I have Navbar.jsx, containing:
// Custom Dependencies
import s from './Navbar.scss';
import NavButton from './NavButton/NavButton';
When I have the app load the components in client/main.jsx with the following:
Meteor.startup(() => {
render(<App />, document.getElementById('render-target'));
});
It works, but it doesn't work when I add either react or flow router and create a route:
FlowRouter.route('/', {
action() {
mount(App);
}
});
It throws the following:
W20160520-10:09:25.659(-7)? (STDERR) Error: Cannot find module './Navbar.scss'
W20160520-10:09:25.659(-7)? (STDERR) at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:78:1)
W20160520-10:09:25.659(-7)? (STDERR) at meteorInstall.imports.ui.Navbar.Navbar.jsx (imports/ui/Navbar/Navbar.jsx:7:1)
W20160520-10:09:25.659(-7)? (STDERR) at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:141:1)
Would appreciate any technical insight as to how I might be able to fix this issue.
Also I would like to note that I've tried relative and absolute pathing, but the fundamental issue is that it only looks for NPM packages the moment I add a router (or at least that's my interpretation of what's happening).
I figured out a solution!
My underlying assumption might be wrong, but I think it has to do with load order. I moved my routes from the standard lib/ folder into my imports/ folder where I also have my other react modules. I then just imported/required the routes in my client/main.jsx and it worked!
I have an application that began in meteor 0.6.0 and has been progressively updated to the current 0.9.3.1 version.
The app uses a local package called "app" which is in ./pacakges/app and it has a package.js file that looks like this:
./packages/app/package.js
Package.describe({
summary: "App SDK",
version: "1.0.0"
});
Package.onUse(function (api) {
api.versionsFrom( '0.9.3.1' );
api.addFiles([
"app.js"
], "server");
api.export([
'amqp',
'eyes',
'fiber',
'eyes',
'pretty',
'sax',
'xml_writer'
], "server" );
});
Npm.depends({
"eyes": "0.1.8",
"amqp": "0.1.6",
"fibers": "1.0.0",
"pretty-data": "0.40.0",
"sax": "0.5.4",
"xml-writer": "1.2.4"
});
This used to work, but I recently checked out a working copy on a new machine and I get the following error when I start meteor:
app: updating npm dependencies -- eyes, amqp, fibers, pretty-data, sax, xml-writer...
W20141003-09:50:13.172(-7)? (STDERR)
W20141003-09:50:13.239(-7)? (STDERR) /root/.meteor/packages/meteor-tool/.1.0.33.vvwxrr++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/dev_bundle/lib/node_modules/fibers/future.js:173
W20141003-09:50:13.239(-7)? (STDERR) throw(ex);
W20141003-09:50:13.239(-7)? (STDERR) ^
W20141003-09:50:13.240(-7)? (STDERR) Error: Cannot find module 'eyes'
W20141003-09:50:13.240(-7)? (STDERR) at Function.Module._resolveFilename (module.js:338:15)
W20141003-09:50:13.240(-7)? (STDERR) at Function.Module._load (module.js:280:25)
W20141003-09:50:13.240(-7)? (STDERR) at Module.require (module.js:364:17)
W20141003-09:50:13.241(-7)? (STDERR) at require (module.js:380:17)
W20141003-09:50:13.241(-7)? (STDERR) at Object.Npm.require (/mnt/disk2/applications/myapp/source/.meteor/local/build/programs/server/boot.js:95:18)
W20141003-09:50:13.241(-7)? (STDERR) at app/server/main.data_sync.js:10:24
W20141003-09:50:13.241(-7)? (STDERR) at /mnt/disk2/applications/myapp/source/.meteor/local/build/programs/server/boot.js:175:5
Since there's a mention of cordova there, I assume this has to do with the recent introduction of that platform to meteor. I am not targeting mobile platforms in my app, so I could remove it if that would help.
The question is, am I missing something to get these npm dependencies honoured?
The answer in this case was that there were calls to Npm.require() outside of the package. I had assumed that npm dependencies set by a package would be made available to the application itself, but that is not true.
In my case I just exported some of the NPM packages I needed through api.export() and removed any Npm.require() calls from the app (except Npm.require('fibers') which is allowed).
There's also this package which allows Npm.require() without packages.
I am a Meteor newbie and just ran into a problem using accounts-google (see below). All I did was follow the instructions on http://docs.meteor.com/#meteor_loginwithexternalservice. Any ideas on how to solve this issue and get Google login working? Thanks!
Terminal output:
W20141003-09:42:57.115(7)? (STDERR)
W20141003-09:42:57.116(7)? (STDERR) /Users/aw/.meteor/packages/meteor-tool/.1.0.33.alt9dq++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/lib/node_modules/fibers/future.js:173
W20141003-09:42:57.116(7)? (STDERR) throw(ex);
W20141003-09:42:57.117(7)? (STDERR) ^
W20141003-09:42:57.118(7)? (STDERR) ReferenceError: ServiceConfiguration is not defined
W20141003-09:42:57.119(7)? (STDERR) at app/server/accounts.js:26:1
W20141003-09:42:57.120(7)? (STDERR) at app/server/accounts.js:35:3
W20141003-09:42:57.120(7)? (STDERR) at /Users/aw/TS/.meteor/local/build/programs/server/boot.js:168:10
W20141003-09:42:57.120(7)? (STDERR) at Array.forEach (native)
W20141003-09:42:57.121(7)? (STDERR) at Function._.each._.forEach (/Users/aw/.meteor/packages/meteor-tool/.1.0.33.alt9dq++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/lib/node_modules/underscore/underscore.js:79:11)
W20141003-09:42:57.121(7)? (STDERR) at /Users/aw/TS/.meteor/local/build/programs/server/boot.js:82:5
=> Exited with code: 8
When I comment out my service configuration code (below)
// first, remove configuration entry in case service is already configured
ServiceConfiguration.configurations.remove({
service: "google"
});
ServiceConfiguration.configurations.insert({
service: "google",
clientId: "xxxxxxxx",
secret: "xxxxxxxxx"
});
It asks me to enter the clientId and secret from the bootstrap dropdown gui. Then nothing happens after that.
After I add service-configuration, I get the following error after logging in:
It turns out that in addition to meteor add service-configuration, you have to complete a minimum of all of the following in Google's API website:
https://console.developers.google.com/project
"Create Project"
Wait for the project to be provisioned
"API & auth" on the sidebar, "Credentials"
"Create new Client ID"
Paste in "Authorized JavaScript origin" and "Authorized Redirect URI"
"Create Client ID"
Copy the Client Secret and Client ID to your app configuration
"API & auth" on the sidebar "Consent screen"
Enter the field "Product Name" and save
Steps 9 & 10 appear to be new requirements from Google in the past few days. See this Github ticket regarding the issue.
You need to meteor add service-configuration manually.
The rest of your code looks good to me.
You also need to make sure that you configured things correctly in the Google Developers Console.
Add http://localhost:3000/_oauth/google?close in the REDIRECT URIS section, as well as http://localhost:3000/ for the JAVASCRIPT ORIGINS section.
This is for testing purpose on localhost, you'll need to add your deployed app actual ROOT_URL (http://www.example.com/) when pushing to production.
I addressed a similar problem here :
Meteor.user is null after (apparently) successful login
After I updated my Meteor app to 0.6.5 using
meteor update
and deployed it to my shared server (webfaction). I have a new error that appeared without me changing the application :
/home/me/webapps/meteor/bundle/programs/server/boot.js:184
}).run();
^
Error: a route URL prefix must begin with a slash
at _.extend.declare (packages/routepolicy/routepolicy.js:95)
at new StreamServer (packages/livedata/stream_server.js:23)
at new Server (packages/livedata/livedata_server.js:1029)
at Package (packages/livedata/server_convenience.js:10)
at packages/livedata.js:3907:4
at packages/livedata.js:3918:3
at /home/me/webapps/meteor/bundle/programs/server/boot.js:153:10
at Array.forEach (native)
at Function._.each._.forEach (/home/me/webapps/meteor/bundle/programs/server/node_modules/underscore/underscore.js:79:11)
at /home/me/webapps/meteor/bundle/programs/server/boot.js:80:5
Downgrading to 0.6.4.1 fixes the issue.
I would very much like to understand why the error is coming with 0.6.5
Check your ROOT_URL. Make sure it starts with http://
It might have something to do with changes to the package API in 0.6.5. See the release notes - http://www.meteor.com/blog/2013/08/14/meteor-065-namespacing-modularity-new-build-system-source-maps
And this meteor-talk thread - https://groups.google.com/d/topic/meteor-talk/BbrjGcGGIzc/discussion