jaredhanson / jaredhanson/connect-flash

Error: req.flash() requires sessions

Open
#47 2 comments 4 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.2k
Forks
173
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the middleware setup in main.js and the shown registration route, then read how connect-flash depends on express-session. Reproduce the req.flash('username') call with the supplied Redis-backed configuration and inspect the session initialization order. Done means the route renders without the sessions error and flash messages still work.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, javascript, redis
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.