derby-auth icon indicating copy to clipboard operation
derby-auth copied to clipboard

db.users.drop() causes trouble

Open ile opened this issue 12 years ago • 3 comments

db.users.drop() seems to cause problems - the code (derby-auth) assumes that everything is ok when the sess.userId is set, but actually the database can be empty, which isn't noticed that that point (https://github.com/lefnire/derby-auth/blob/master/index.js#L64), and it will lead to problems afterwards.

The client has to have a cookie set in order the sess.userId to be set (of course).

ile avatar Feb 18 '13 23:02 ile

Hit me up with a PR if you can think of a work around, or any suggestions on handling configurable collection name?

On Mon, Feb 18, 2013 at 6:30 PM, Ilkka Huotari [email protected]:

db.users.drop() seems to cause problems - the code (derby-auth) assumes that everything is ok when the sess.userId is set, but actually the database can be empty, which isn't noticed that that point ( https://github.com/lefnire/derby-auth/blob/master/index.js#L64), and it will lead to problems afterwards.

— Reply to this email directly or view it on GitHubhttps://github.com/lefnire/derby-auth/issues/20.

lefnire avatar Feb 18 '13 23:02 lefnire

Not sure, but should it just do a model.fetch around that point (line 64)? Of course an extra model.fetch feels bad though...

In the app code there will probably be this: model.set '_user', user

... would it be wise to do that at the derby-auth level already?

Just some ideas, I really don't know what's best here..

ile avatar Feb 18 '13 23:02 ile

Here's one way to do it (maybe): https://github.com/ile/derby-auth/commit/5207118c0516325e4f8c56fd50e225b129ecdf7a

(A bit too much code got in. I'm also making hooks for users_public collection because I think that's what I need... By querying users_public I get a hash array and not a normal array like with motifs .... so maybe a PR isn't a good idea with this commit)

You can decide what to do with this, copy & paste or improve or anything.

ile avatar Feb 19 '13 02:02 ile