3

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?

1 Answer 1

3

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!'); });
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I wasn't sure how the Connect/Express syntax translated to pure node.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.