Just use mongoose-auth from Brian Noguchi https://github.com/bnoguchi/mongoose-auth
This solution is for your question, it is well documented and extensible.
EDIT
mongoose-auth no longer supported. If you need to make it work with later versions of mongoose (i.e.> v3.xx) and express (i.e.> V3.xx), here is an excerpt from the package.json file that I am currently using in production (it hacked but it works):
"everyauth": "https://github.com/bnoguchi/everyauth/tarball/express3", "mongoose-3x-types": "~1.0.5", "mongoose-auth": "https://github.com/cbou/mongoose-auth/tarball/everymodule-fix",
I you start a new project , do not use mongoose-auth , but try passport , It offers the same functionality that it is very flexible, however it has a different api. It is part of the locomotive MVC structure and is therefore actively supported.
alexandru.topliceanu Dec 28 2018-11-12T00: 00Z
source share