passport-local-mongoose
passport-local-mongoose copied to clipboard
Cannot access hash of a logged in user
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?
getting the same result for account.get('hash')
the hash is valid and exists in the db
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
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.