问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/27291137/users-management-in-node-js-with-express-mongodb-as-server-database