How it works...
Our /routes/api/login.js route configuration is a stand-alone route configuration and middleware for handling authentication in our Express application. Usually, middleware that is reusable would be put in our /middleware directory for easy access. However, in this case, our login middleware is only used by this same route configuration, so it is simpler to just include it in the same place as the route configuration.
Our user store is a simple JSON array of user objects that contain all the fields that define a user, including a password and role field. It's worth noting that storing a password as plain text such as this is not a good idea in a production environment. In a real application, we would want to hash this password ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access