Book Image

Building Scalable Apps with Redis and Node.js

By : Joshua Johanan
Book Image

Building Scalable Apps with Redis and Node.js

By: Joshua Johanan

Overview of this book

Table of Contents (17 chapters)
Building Scalable Apps with Redis and Node.js
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Let's build our authentication


With our packages installed, we now have the basis to build our authentication system. The first thing to do is create a folder named passport and create a file named index.js in that folder. Inside index.js, we will get a reference to Passport and pass it back to the main app.js, as shown in the following code:

var passport = require('passport');

exports.passport = passport;

We could have done this in app.js, but we are going to set some things up and add some utility functions to this object. This will help keep our app.js file clean and easy to understand. We can now jump over to app.js and use our new module. Add the following lines to app.js:

//at the top with variable declarations
passport = require('./passport');
//in the middleware section
app.use(session({
  secret: config.secret,
  saveUninitialized: true,
  resave: true,
  store: new RedisStore(
    {url: config.redisUrl})
  })
);
app.use(passport.passport.initialize());
app.use(passport.passport.session...