6

Looking for the way to add user management to my site.

Site: Working with Node.js & Express, when creating the initial project with Express, the app.js file contains these lines:

app.use('/', routes);
app.use('/users', users);

In addition, a file users.js is created under routes folder. My question is how to manage users, force login, and show different views for regular user / admin user. I wish to find a simple example / tutorial.

Storage: Working with MongoDB & mongoose, I noticed the database has Users folder built-in. I want to save users data (user + password + preference) on MongoDB. What is the way to do this?

Keren
  • 407
  • 2
  • 7
  • 20
  • 2
    You could use Passport JS for this. Follow this [tutorial](http://danialk.github.io/blog/2013/02/23/authentication-using-passportjs/) for more details and this [GitHub repo](https://github.com/DanialK/PassportJS-Authentication). – chridam Dec 04 '14 at 10:16
  • Is there a way to do so in express? I'm not interested in security, I prefer simplicity. (This is a site in a private net). It looks like express set the ground for it, I just couldn't find any example. – Keren Dec 04 '14 at 10:33
  • Not sure if that can be done entirely in express though [Stormpath](https://stormpath.com/blog/finally-manage-users-easily-in-node-dot-js/) ([or tutorial here](https://stormpath.com/blog/build-app-nodejs-express-passport-stormpath/)) looks like what you need. – chridam Dec 04 '14 at 10:38
  • 2
    Of course you COULD do it in express only but you'd have to write all the stuff again that is in libraries like passport or stormpath – Laura Dec 04 '14 at 11:55
  • Look up "express-user" and "express-user-local" on the npm registry. Keep in mind that atm, they are still alpha and subject to frequent backward breaking changes. – Magnitus Mar 08 '15 at 19:20

1 Answers1

7

I followed this tutorial. https://scotch.io/tutorials/easy-node-authentication-setup-and-local

Passport js does the job very nicely, doing this without a library would just require you to reinvent the wheel.

juunas
  • 54,244
  • 13
  • 113
  • 149