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

I created a simple nodejs application using nodejs + express. Now I want to do user authentication. I want to implement session processing using mongoose. Can you recommend some examples?

+50
authentication mongoose express
Dec 6 2018-11-11T00:
source share
3 answers

Some useful links:

how to implement login auth in node.js

creating a registration form and registration in node.js and mongodb

Also, session management is not performed by Mongoose, but via connect-mongodb or connect-redis. You can check an example of using user rights and session management in a real application:

https://github.com/alexyoung/nodepad/blob/master/app.js

You can find further explanations of this application here: http://dailyjs.com/tag/lmawa or http://dailyjs.com/2010/12/06/node-tutorial-5/

+47
Dec 06 2018-11-11T00:
source share

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.

+14
Dec 28 2018-11-12T00:
source share

I posted a complete example of a complete auth system using mongoose + expressjs here if you want to take a look:

Simple nodejs login page using express and passport with mongodb

+5
Sep 26 '13 at 20:13
source share



All Articles