0

I have been trying to do the google oauth by following a tutorial and i am getting this error . Though the above question has already been answered once but still I could not figure out as what is wrong in the order that i have used . Here is my index.js

const express=require('express');
const app=express();
const cookieSession=require('cookie-session');
const keys=require('./config/keys');
const mongoose=require('mongoose');
const passport=require('passport');
require('./models/User');
require('./services/passport');

mongoose.connect(keys.mongoURI,{ useNewUrlParser: true });

require('./routes/authRoutes')(app);

app.use(
 cookieSession({
    maxAge:30*24*60*60*1000,
    keys:[keys.cookieKey]

 })
);


app.use(passport.initialize());
app.use(passport.session());

const PORT=process.env.PORT || 5000;

app.listen(PORT);

Here is the github link to repo.github

jammy
  • 857
  • 2
  • 18
  • 34
  • 2
    Try moving `require('./routes/authRoutes')(app)` to right above `app.listen(...)`. – robertklep Sep 10 '18 at 17:27
  • Yes,it actually worked .What can be the reason for this? – jammy Sep 10 '18 at 17:31
  • The order in which middleware is declared is important. See also [this question](https://stackoverflow.com/questions/16781294/passport-js-passport-initialize-middleware-not-in-use) (which is almost a duplicate of yours). – robertklep Sep 10 '18 at 17:34

0 Answers0