Creating user with no password in Meteor

accounts, authentication, meteor

Solution

- Register `onCreateUser` to add an "anonymous" field (`{anonymous:1}`) when a random password is used, maybe generated with `Meteor.uuid()`.

- Add a timestamp field (`{created:new Date()}`) to clean out old, anonymous accounts.

- Perform old anonymous user maintenance, like deleting anonymous users more than one hour old: `Meteor.autorun(function() {Meteor.users.find({anonymous:1,$where:"new Date() - this.created > 360000"}).forEach(function (user) { Meteor.users.remove({_id:user._id})}});`

- On the client:

- Always prompt for a "nickname." This will become the official username, or will sit in the system forever used.

- Check if client is logged in. If not, create a user with nickname and a "magic number" password, which logs you in. When they click register, write "Register" at the top, but actually just change their password and `$set:{anonymous:0}`

Don't use localStorage, and don't use UIDs. The session cookie IS your UID.

Problem

I have a unique user creation flow which is as follows: - User comes to my site for the first time and they click a button. - I create a User in the DB for them and set a localStorage key with the UID. - Use goes about creating data and I save the data in the DB and associate it with the UID. - User comes back, and if they have UID set in localStorage, I show them the data they previously created. - User can click Register to create a "real" account from which point they will have to login with username and password or another service (e.g. Facebook). So, how would I accomplish this with Meteor Accounts and the User model? In a nutshell: - I need to create User mongo document with no information (about the user). - I need to authenticate a user by just having a UID (acting as a "password").

Original source