Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: req.flash() requires sessions #47

Open
lbois opened this issue Apr 16, 2020 · 2 comments
Open

Error: req.flash() requires sessions #47

lbois opened this issue Apr 16, 2020 · 2 comments

Comments

@lbois
Copy link

lbois commented Apr 16, 2020

Hello

I get the error "Error: req.flash() requires sessions" using connect-flash, I use Express 4.17... I do not understand it seems my setup is correct.
Here is my main.js

const Session = require('express-session');
const redis = require('redis');

let RedisStore = require('connect-redis')(Session)
let redisClient = redis.createClient()

app.use(flash());
app.use(Session({
    store: new RedisStore({ client: redisClient }),
    secret: config.server.secret,
    cookie: {maxAge: Date().now + (60 * 1000 * 30) } ,
    resave: false, 
    saveUninitialized: false
}));

Here is the code of the route where the error come from

const express = require('express'),
    router = express.Router(),
    passport = require('passport');
 
router.get('/',
    require('connect-ensure-login').ensureLoggedOut(),
    (req, res) => {
        res.render('register', {
            user : null,
            errors : {
                username : req.flash('username'), <-- error here
                email : req.flash('email')
            }
        });
    });

Redis is started up

Thanks for your help

Laurent

@lbois
Copy link
Author

lbois commented Apr 16, 2020

I fixed the problem.
Router after flash.
Please close this issue

@Alieltahan
Copy link

@lbois , Please note you may close it by your self.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants