Categories
JavaScript Answers

How to fix req.user Undefined with Node, Express and Passport?

Spread the love

To fix req.user Undefined with Node, Express and Passport, we add the Passport middlewares.

For instance, we write

app.use(session({ secret: "anything" }));
app.use(passport.initialize());
app.use(passport.session());

to add Passport into our Express app by calling app.use with the middlewares returned by passport.initialize and passport.session.

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 *