Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor: onUserCreation

Tags:

meteor

I'm very new to Meteor and already have so many headaches.. perhaps anyone can explain the following:

I'm using the Josh Owen entry package for FB, G+, etc login. Eventually I want to add more fields to the user collection. But for now I was just testing and logging to console:

Accounts.onCreateUser(function(options, user) {
    console.log(user);
});

And in console I get the following error:

I20141217-13:38:57.958(1)? { createdAt: Wed Dec 17 2014 13:38:57 GMT+0100 (CET),
I20141217-13:38:58.046(1)?   _id: 'iq6B8PqDxfg8MntwB',
I20141217-13:38:58.047(1)?   services:
I20141217-13:38:58.047(1)?    { facebook:
I20141217-13:38:58.047(1)?       { accessToken: 'CAAKjw0F4gZB0BAC1pAoHk4NnILGw3KGSYThe58epe8xK7FXcXZBy0LPsVwlK5KXmmazjrnI1fbGhyhAioxiHxJkHNdgi0a9TFCzKXzhFCOZCSwapXWbwJJAna4uiTUA8ZAN0w9Qwh8ZB6lQSqV0eBdo8lNCFGZCsYJYq2wZAf2YmVUVCVLZBNphZAq463JKSiECZClyfynPmowGEuH5lGZCX8Q0',
I20141217-13:38:58.047(1)?         expiresAt: 1423941428713,
I20141217-13:38:58.047(1)?         id: '10152814253281413',
I20141217-13:38:58.048(1)?         email: 'l******m',
I20141217-13:38:58.048(1)?         name: 'Lowen Flowen',
I20141217-13:38:58.048(1)?         first_name: 'Lowen',
I20141217-13:38:58.048(1)?         last_name: 'Flowen',
I20141217-13:38:58.048(1)?         link: 'https://www.facebook.com/app_scoped_user_id/10152814253281413/',
I20141217-13:38:58.048(1)?         gender: 'male',
I20141217-13:38:58.049(1)?         locale: 'en_US' } } }
I20141217-13:38:58.049(1)? Exception while invoking method 'login' Error: insert requires an argument
I20141217-13:38:58.049(1)?     at Mongo.Collection.(anonymous function) [as insert] (packages/mongo/collection.js:465)
I20141217-13:38:58.049(1)?     at Object.Accounts.insertUserDoc (packages/accounts-base/accounts_server.js:1042)
I20141217-13:38:58.050(1)?     at Object.Accounts.updateOrCreateUserFromExternalService (packages/accounts-base/accounts_server.js:1189)
I20141217-13:38:58.050(1)?     at Package (packages/accounts-oauth/oauth_server.js:45)
I20141217-13:38:58.050(1)?     at packages/accounts-base/accounts_server.js:383
I20141217-13:38:58.050(1)?     at tryLoginMethod (packages/accounts-base/accounts_server.js:186)
I20141217-13:38:58.050(1)?     at runLoginHandlers (packages/accounts-base/accounts_server.js:380)
I20141217-13:38:58.050(1)?     at Meteor.methods.login (packages/accounts-base/accounts_server.js:434)
I20141217-13:38:58.051(1)?     at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1594)
I20141217-13:38:58.051(1)?     at packages/ddp/livedata_server.js:648
like image 790
flowen Avatar asked Dec 17 '14 12:12

flowen


1 Answers

You have to return user. Example from Meteor docs:

// Support for playing D&D: Roll 3d6 for dexterity
Accounts.onCreateUser(function(options, user) {
  var d6 = function () { return Math.floor(Random.fraction() * 6) + 1; };
  user.dexterity = d6() + d6() + d6();
  // We still want the default hook's 'profile' behavior.
  if (options.profile)
    user.profile = options.profile;
  return user;
});

You can use console.log(user); before return statement.

like image 145
Tomas Hromnik Avatar answered Nov 03 '22 22:11

Tomas Hromnik