Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access hash of a logged in user #248

Open
navxio opened this issue May 16, 2018 · 3 comments
Open

Cannot access hash of a logged in user #248

navxio opened this issue May 16, 2018 · 3 comments

Comments

@navxio
Copy link

navxio commented May 16, 2018

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
Copy link
Author

navxio commented May 21, 2018

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

the hash is valid and exists in the db

@Filliposniper
Copy link

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

@coldfire84
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants