Joe
Joe

Reputation: 183

Using node.js client-sessions without express

I'm trying to get client-sessions to work without using express but I'm not sure if I'm porting the example correctly.

var sessionOptions = { cookieName: 'mySession', secret: 'blargadeeblargblarg', duration: 24 * 60 * 60 * 1000, activeDuration: 1000 * 60 * 5 }; var session = new SESSION(request, response, {}, sessionOptions);

When I run this client-sessions complains

cannot set up sessions without a secret or encryptionKey/signatureKey pair

Does client-sessions need express to work?

Upvotes: 3

Views: 4409

Answers (1)

olan
olan

Reputation: 3648

From https://github.com/mozilla/node-client-sessions:

client-sessions is connect middleware

So while it might not need express, it needs connect to work as per the docs.

The specific error though, is because you aren't using the library correctly. You need to configure a session before using it.

var sessions = require("client-sessions");

var session = sessions({
  cookieName: 'mySession',
  secret: 'blargadeeblargblarg', 
  duration: 24 * 60 * 60 * 1000, 
  activeDuration: 1000 * 60 * 5
});

// then inside route handler..
session(req, res, function(){ console.log('done!'); });

Upvotes: 3

Related Questions