Tuesday, 2 May 2017

Angular login prompts for credentials everytime when node server restarts

I think, there is some issue with session storage. I am using generator-angular-fullstack.

Code looks good, still not able to identify where's the issue :(

  app.use(compression());
  app.use(bodyParser.urlencoded({extended: false}));
  app.use(bodyParser.json());
  app.use(methodOverride());
  app.use(cookieParser());
  app.use(morgan('dev'));
  app.use(passport.initialize());
  app.use(passport.session());
  app.use(session({
    secret: config.secrets.session,
    saveUninitialized: true,
    resave: false,
    store: new MongoStore({
      db: 'temp',
      mongooseConnection: mongoose.connection,
    }, function (err) {
      console.log(err || 'Connect-mongodb setup successfull.');
    })
  }));

And, session gets stored in a collection having data. i.e.

{
    "_id" : "T532RSGL-HMbKeKF3B3_CKw7w9ChpTI3",
    "session" : "{\"cookie\":{\"originalMaxAge\":null,\"expires\":null,\"httpOnly\":true,\"path\":\"/\"},\"_csrfSecret\":\"ivu20vVoAJjkNw==\"}",
    "expires" : ISODate("2017-05-16T09:35:11.211Z")
}

But whenever i do any changes in server code, it requires restart, and i need to login again and again after every restart.

Any help would be appreciated. Thanks :)



via Manish Singh

No comments:

Post a Comment