Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nestjs: @Session() return undefined

Tags:

express

nestjs

I am currently migrating my server to use nest.js. When I use the @Session() decorator it gives me undefined. I do import it from @nestjs/common, this is not the issue.

@Get('foo')
async find(@Session() sess) {
  console.log(sess); // sess == undefined
}

While, with express the session is defined

router.get('/foo/', function(req, res){
  console.log(req.session); // req.session is defined

Thanks for your help!

like image 808
Alexandre Fradette Avatar asked Jan 28 '23 02:01

Alexandre Fradette


1 Answers

The session middleware is not applied by default, you have to do it manually:

app.use(session({ secret: 'nest is awesome' }))
like image 90
Kamil Myśliwiec Avatar answered Jan 31 '23 05:01

Kamil Myśliwiec