User documents have ids when onCreateUser and validateNewUser hooks run

This commit is contained in:
Avital Oliver
2013-02-26 16:33:38 -08:00
parent df56063632
commit 344a3bb003
2 changed files with 21 additions and 3 deletions

View File

@@ -122,9 +122,19 @@
return user;
};
Accounts.insertUserDoc = function (options, user) {
// add created at timestamp (and protect passed in user object from
// modification)
user = _.extend({createdAt: +(new Date)}, user);
// - clone user document, to protect from modification
// - add createdAt timestamp
// - prepare an _id, so that you can modify other collections (eg
// create a first task for every new user)
//
// XXX If the onCreateUser or validateNewUser hooks fail, we might
// end up having modified some other collection
// inappropriately. The solution is probably to have onCreateUser
// accept two callbacks - one that gets called before inserting
// the user document (in which you can modify its contents), and
// one that gets called after (in which you should change other
// collections)
user = _.extend({createdAt: +(new Date), _id: Random.id()}, user);
var result = {};
if (options.generateLoginToken) {

View File

@@ -7,6 +7,14 @@ Tinytest.add('accounts - config validates keys', function (test) {
});
});
Tinytest.add('accounts - validateNewUser gets passed user with _id', function (test) {
Accounts.validateNewUser(function (user) {
test.equal(typeof user._id, "string");
return true;
});
Accounts.updateOrCreateUserFromExternalService('foobook', {id: Random.id()});
});
Tinytest.add('accounts - updateOrCreateUserFromExternalService - Facebook', function (test) {
var facebookId = Random.id();