mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
User documents have ids when onCreateUser and validateNewUser hooks run
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user