Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 some example?

like image 261
Erik Avatar asked Dec 06 '11 09:12

Erik


People also ask

How do I use basic authentication in node JS?

Explanation: The first middleware is used for checking the authentication of the client when the server start and the client enter the localhost address. Initially req. headers. authorization is undefined and next() callback function return 401 status code unauthorized access to the browser.


1 Answers

Some useful links:

how to implement login auth in node.js

creating registration and login form in node.js and mongodb

Also session management isn't done by Mongoose, but by connect-mongodb or connect-redis. You can checkout an example on how to do user auth and session management in a real application here:

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

Further explanations for that app you can find here: http://dailyjs.com/tag/lmawa or http://dailyjs.com/2010/12/06/node-tutorial-5/

like image 87
alessioalex Avatar answered Sep 23 '22 22:09

alessioalex