Categories
JavaScript Answers

How to fix passport.js passport.initialize() middleware not in use with Node.js?

Spread the love

To fix passport.js passport.initialize() middleware not in use with Node.js, we call app.use with the middleware returned by initialize.

For instance, we write

app.use(
  cookieSession({
    maxAge: 30 * 24 * 60 * 60 * 1000,
    keys: [keys.cookieKey],
  })
);
app.use(passport.initialize());
app.use(passport.session());

to call app.use with the function returned by initialize to add Passport to our Express app.

We call cookieSession to return a middleware to let us use cookie sessions.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *