Users management in node js with express, mongodb as server database [closed]
Asked Answered
T

1

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?

Thresher answered 4/12, 2014 at 10:5 Comment(5)
You could use Passport JS for this. Follow this tutorial for more details and this GitHub repo.Noddle
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.Thresher
Not sure if that can be done entirely in express though Stormpath (or tutorial here) looks like what you need.Noddle
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 stormpathThreepence
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.Roden
I
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.

Iyre answered 4/12, 2014 at 12:24 Comment(2)
The link no longer worksSulphurous
Thanks for the notice, fixed :)Iyre

© 2022 - 2024 — McMap. All rights reserved.