简体   繁体   中英

How to make a single user authentication and authorization? Or how to restrict number of users registering to an application in node js?

I want to make a simple app using MERN ( Mongo , Express , React , Node ), in which only one person will have to upload pics or write a blog; clients can only view in general. So, I want to create one user authentication. How can I achieve this?

  • Store sessions in the database
  • Add a field called, say, "inuse" to the session document
  • Set that field to 1 when storing the session
  • Add a unique index with that key

This will prevent your application from being able to store more than one session at a time.

You would then need to devise a mechanism for expiring sessions that are abandoned (ie user doesn't explicitly click "log out" button) as well as figure out what to do if, say, your browser crashes and you can't use the established session but it's still within the session inactivity timeout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM