keystone-5 icon indicating copy to clipboard operation
keystone-5 copied to clipboard

Example for sessionStore config in the docs for Keystone 5 is outdated

Open leopoldkristjansson opened this issue 3 years ago • 0 comments

Bug report

Describe the bug

The following code example seems outdated:

const expressSession = require('express-session');
const MongoStore = require('connect-mongo')(expressSession);

const keystone = new Keystone({
  sessionStore: new MongoStore({ url: 'mongodb://localhost/my-app' }),
});

from:

https://www.keystonejs.com/keystonejs/keystone/#sessionstore

It returns an error

✔ Keystone server listening on port 3000
✖ Initialising Keystone instance
TypeError: Class constructor MongoStore cannot be invoked without 'new'
    at Object.<anonymous> (/folder/project-using-keystone/index.js:18:44)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1019:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at executeDefaultServer (/folder/project-using-keystone/node_modules/@keystonejs/keystone/bin/utils.js:140:7)
error Command failed with exit code 1.

Additional context

It looks to me like the following code is the way to go, but it does not use express-session at all.

const MongoStore = require('connect-mongo');

const keystone = new Keystone({
  sessionStore: MongoStore.create({ mongoUrl: process.env.MONGO_URI }),
});

leopoldkristjansson avatar May 13 '21 11:05 leopoldkristjansson