passport-local-mongoose icon indicating copy to clipboard operation
passport-local-mongoose copied to clipboard

Cannot access hash of a logged in user

Open navxio opened this issue 6 years ago • 3 comments

try {
   account = await Account.findById(userid)
 } catch (e) {
   throw e
 }

I'm trying to access the hash property directly using the loaded account, with account.hash but it's undefined... am I doing something wrong?

navxio avatar May 16 '18 08:05 navxio

getting the same result for account.get('hash')

the hash is valid and exists in the db

navxio avatar May 21 '18 08:05 navxio

Got same problem can't find the hash and salt from the callback, any help or way around this.. I need to hash a password

Filliposniper avatar Jun 20 '18 23:06 Filliposniper

For anyone else that ends up here, you can return hash/ salt using the following:

var accountWithHash = await Account.findByUsername(username, true);

From the docs:

findByUsername() convenience method to find a user instance by it's unique username.

What I didn't find in the docs but did in reviewing the source code, is that you can include salt and hash fields in the returned object, if the second parameter is a boolean and set to 'true': https://github.com/saintedlama/passport-local-mongoose/blob/master/index.js#L283

These attributes are intentionally filtered out of Account.findOne() / Account.findById() methods.

coldfire84 avatar Jan 04 '20 10:01 coldfire84