Mongoose password hashing

前端 未结 10 960
盖世英雄少女心
盖世英雄少女心 2020-12-04 07:28

I am looking for a good way to save an Account to MongoDB using mongoose.

My problem is: The password is hashed asynchronously. A setter wont work here because it on

10条回答
  •  时光取名叫无心
    2020-12-04 07:56

    I guess it would be better to use the hook, after some research i found

    http://mongoosejs.com/docs/middleware.html

    where it says:

    Use Cases:

    asynchronous defaults

    I prefer this solution because i can encapsulate this and ensure that an account can only be saved with a password.

提交回复
热议问题