Rostislav Shtanko
Rostislav Shtanko

Reputation: 724

Cannot store data in koa.js app using koa-session

I'm using koa-session in my koa-app to store some data. So here is my code:

/*some code*/
app.use(session(app));
/*some code*/
router.get('/test', async (ctx) => {
    const {session} = ctx;

    console.log(session['test']) // always undefined

    session['test'] = 'test'
});

I'm expect to get undefined on the first request and 'test' on the other requests, but I'm always getting undefined. What is wrong with this code?

Upvotes: 0

Views: 517

Answers (1)

shobeurself
shobeurself

Reputation: 128

try

ctx.session.test = "testsessiondata"

Upvotes: 1

Related Questions