gx0r/connect-session-knex

Cannot set property 'domain' of undefined

Closed this issue · 3 comments

Using the example, I have the following:

import express from 'express';
import session from 'express-session';
import knexSessionStore from 'connect-session-knex';
import {knex} from './db';

const app = express();

app.use(session({
  secret: 'notsosecret',
  resave: false,
  saveUninitialized: false,
  cookie: { maxAge: 60000 },
  store: knexSessionStore(session)({knex})
}));

The error has the following stack trace:

[2] [piping] error given was: TypeError: Cannot set property 'domain' of undefined
[2]     at EventEmitter.init (events.js:43:15)
[2]     at EventEmitter (events.js:12:21)
[2]     at Store (/Users/rb/dev/mydrip/node_modules/express-session/session/store.js:33:16)
[2]     at KnexStore (/Users/rb/dev/mydrip/node_modules/connect-session-knex/index.js:91:9)
[2]     at Object.<anonymous> (api.js:27:10)
[2]     at Module._compile (module.js:541:32)

express: 4.13.3
express-session: 1.14.0
node: 6.3.1

I've been unable to pin down what the problem is. Any idea?

Just updated the initial post with the node version since I realised this may have something to do with it.

gx0r commented

Not sure what is the problem. It seems like possibly some sort of environmental issue. Could you build a clonable repo with a reproducible test case? Oftentimes that can accelerate finding a solution since it may be related to babel or some dependency issue.

So I've managed to fix this (at least in a hacky way). It turns out this was undefined when KnexStore was being called. So instead of just calling it with the initialise options, I instead used the new operator to create an instance of it with the initialise options. In code:

before

{
    ...,
    store: knexSessionStore(session)({knex})
}

after

{
    ...,
    store: new (knexSessionStore(session))({knex})
}

It's messy, I know, and I'm not entirely sure how this worked before, but it definitely works now. Thank you for following up on this though @llambda