meteor-collection-behaviours icon indicating copy to clipboard operation
meteor-collection-behaviours copied to clipboard

softRemovable not in place when creating new user

Open dalgard opened this issue 10 years ago • 2 comments

Applying behaviours to the Meteor.users collection is working fine like this:

CollectionBehaviours.extendCollectionInstance(Meteor.users);
Meteor.users.softRemovable();

When I delete a user, the document remains in the database, but is not returned from Meteor.users.find() – great! The problem arises when the user tries to create a new account with the same e-mail. Meteor says that a user already exists with that e-mail.

Anything I/we can do about this? Thanks.

dalgard avatar Jan 25 '15 21:01 dalgard

I've solved this by redefining the softRemovable behaviour. It's only a small change. In the new version, when applying the behaviour, a modifier object can be passed as an argument.

The new modifier (defaulted to an empty object) is then extended (using _.default) with the base modifier used inside the .before.update hook, which would normally just $set removed and removedAt. The new modifier is used in place of the base modifier in the update operation.

In regard to the Meteor.users collection, I pass the object below as the new modifier – this way, when creating new users in the future, the duplicate check comes out negative.

Meteor.users.softRemovable({
  $rename: {
    "emails": "removedEmails",
    "services": "removedServices"
  }
});

dalgard avatar May 10 '15 00:05 dalgard

http://atmospherejs.com/zimme/collection-softremovable

zimme avatar Jun 05 '15 07:06 zimme