Saturday, 28 July 2018

[HELP] req.flash() requires sessions but sessions exist already

I am trying to just hit a simple `/` route and use `res.send()` to make sure it works. I am getting `req.flash() requires sessions` but I already have sessions set up using a Redis instance.I have spent about 2 hours on Stack overflow trying to find a solution, I have tried many things and nothing has worked. Please so not link to a post saying duplicate unless you know for sure it is the solution.**App.js**const express = require("express"),app = express(),mongoose = require("mongoose"),session = require('express-session'),flash = require('express-flash'),RedisStore = require('connect-redis')(session),bodyParser = require("body-parser"),passport = require("passport"),LocalStrategy = require("passport-local"),methodOverride = require("method-override");// Modelsconst User = require("./models/user");// Configurationconst config = require("./config/config");mongoose.connect(config.db);app.use(bodyParser.urlencoded({extended: true}));app.set("view engine", "ejs");// set sessionapp.use(session({resave: true,saveUninitialized: false,cookie: {maxAge: 60 * 1000 * 60 * 24 * 30 // 30 days},secret: config.sessionSecret,store: new RedisStore({url: "redis://localhost/sail",auto_reconnect: true})}));app.use(express.static(__dirname + "/public"));app.use(methodOverride("_method"));app.use(flash());// PASSPORT CONFIGURATIONapp.use(passport.initialize());app.use(passport.session());passport.use(new LocalStrategy(User.authenticate()));passport.serializeUser(User.serializeUser());passport.deserializeUser(User.deserializeUser());app.get('/', (req, res) => {res.send('hello world');});module.exports = app;

Submitted July 28, 2018 at 07:43PM by jsdfkljdsafdsu980p

No comments:

Post a Comment