How to do authentication with Node.js, Express and Mongoose?

前端 未结 3 595
遇见更好的自我
遇见更好的自我 2020-12-22 15:35

I\'ve made simple nodejs application by using nodejs+express. Now I want to make user authentification. I want to realize session handling by using mongoose. Can you advise

3条回答
  •  误落风尘
    2020-12-22 16:11

    Just use mongoose-auth by Brian Noguchi https://github.com/bnoguchi/mongoose-auth

    It's a drop in solution for your question, it's well documented and extensible.

    EDIT

    mongoose-auth is no longer maintained. If you need to make it work with more recent versions of mongoose (ie > v3.x.x) and express (ie. > v3.x.x), here's an excerpt from a package.json file I'm currently using in production (It's hacky 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 are starting a new project don't use mongoose-auth, instead try out passport. It offers the same functionality, it's very flexible, however it has a different api. It's part of the locomotive MVC framework and as such it's actively maintained.

提交回复
热议问题