session icon indicating copy to clipboard operation
session copied to clipboard

automatically add .createSession(), .load(), and .regenerate() to Store

Open dwhieb opened this issue 9 years ago • 2 comments

As explained in #349, developers who want to write their own Store implementation for express-session face one of two choices:

  1. include express-session as a dependency and extend their Store from store.js
  2. reimplement the functionality of store.js, session.js, and cookie.js (or copy the files from express-session, which amounts to including it as a dependency, but without the benefit of avoiding redundant code)

For many people (myself included), I expect neither of these options is appealing. So instead of requiring the Store implementation to include .createSession(), .load(), and .regenerate(), I suggest that these methods be added to the Store object by express-session on initialization, similar to the way that .generate() is added to the Store here. Couldn't .createSession(), .load(), and .regenerate() be added to the Store in the same way?

These methods could either be moved to index.js like .generate(), or generate() could be moved to store.js, and the methods in store.js could be added to the Store on initialization.

I'm happy to create a PR if this is an improvement you'd like to see implemented.

dwhieb avatar Aug 30 '16 04:08 dwhieb

Hm, I'm not sure; would have to think about the best way. There is no hurry, since neither solution is going to be backwards-compatible anyway, and with the dozens of store modules out there that will be required, we want to make sure we have everything in line with that kind of change, including evangelism.

Do you know what most of the store module are doing today? Which method would have the least impact on them? You can probably at least survey all the modules we have listed in the README (especially since we are advertising them for people to use).

dougwilson avatar Aug 30 '16 04:08 dougwilson

Good to know. I'll do some more looking into this, but in the stores I've looked at so far (about 10 of them), they all extend from express-session's store. connect-redis even requires you to pass the express-session object to it upon initialization, just so it can extend from it.

I'll put some thought into how this might be implemented with the least impact.

dwhieb avatar Aug 30 '16 04:08 dwhieb