How to use methods like .onCreateUser in Meteor 1.3?

Playing with 1.3 and trying to figure out what I use for all my imports. NPM packages are easy to figure out, but what do I do for Meteor methods?

For example, in 1.2 I use:
Accounts.onCreateUser(function (options, user){}

So in 1.3 I need to import Accounts, but from where?
import Accounts from 'meteor/meteor';// doesn’t work
import accountsServer from 'meteor/meteor'; // Docs actually say this method is accountsServer.onCreateUser, but doesn’t work.
import Accounts from 'meteor/accounts-base'; // stabbing in the dark

1 Like

You can still use the global variables just like before! But if you want, you can switch to using imports. I’m going to go through and document how to import all of the functions soon, it’s not ready yet since it is a beta after all.

Oh cool. That does work. I assumed that if I was using imports at all, everything had to be imported. It is nice knowing where everything is coming from — so I look forward to the updated documentation!

1 Like

If you want imports, try this:

import {Accounts} from 'meteor/accounts-base';

AFAIK, meteor packages don’t use default exports

@sashko So now that I cleared out some other errors and I run this function I actually get this error:
Uncaught TypeError: Accounts.onCreateUser is not a function meteorInstall.lib.createUser.js @ createUser.js:3 fileEvaluate @ install.js:183 require @ install.js:75 (anonymous function) @ app.js?hash=fb6c5809bb22af516adcaf9bbad2e667e78f4001:94944

Did it work in Meteor 1.2? Do you have all of the right packages and stuff?

Yeah, works fine in 1.2. I’m playing around in porting to 1.3 (using beta4), though. I do have accounts-password package installed and I can create users, login, logout.

Interesting. It’s hard to see what the issue is without seeing the code.

I’ll create a new repo. I’m using the Mantra kickstarter as base and I might as well do it with beta8. Will report back soon.

Ok, this is a Mantra Kickstarter app that I’m just trying to add an Accounts.onCreateUser() using 1.3 beta 8

In my 1.2 app, I just have a CreateUser.js file in /lib that when a new user is created, pulls profile info from 3rd parties registers (facebook,google) and sends a welcome email. In this repo, /lib/createUser.js is super dumbed down.

git clone
npm install
meteor --port 5000

Will load with white screen, but dev console will have error: Uncaught TypeError: Accounts.onCreateUser is not a function

Can comment out everything in createUser.js and everything will work again.

1 Like

Note that onCreateUser is a server-only function. If you still want the functionality on the client, you can move it to the callback for createUser

@reoh Well that was the simple obvious solution that I overlooked. Move it to server folder. Just tried out the Meteor Modules-todo-react sample app plugged Accounts.onCreateUser into it and worked fine. Thanks for keeping engaged until I worked it out!

1 Like