O'Reilly logo

Building Scalable Apps with Redis and Node.js by Joshua Johanan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required