Very simple authentication
We want everyone who goes to /chat
to be authenticated. We will build a very simple, yet very insecure, authentication system. We will then gut this and put in a real authentication system later, but this exercise will show us how all the pieces we have talked about work together. The first thing is to check if a user is logged in during a request. We will use middleware for this. Open up our utilities.js
from the middleware
folder, and add two new functions.
The first function is to add an isAuthenticated
variable for our templates, which we will use shortly. The following is our function:
module.exports.authenticated = function authenticated(req, res, next){ res.locals.isAuthenticated = req.session.isAuthenticated; if ...
Get Building Scalable Apps with Redis and Node.js now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.