lundi 4 janvier 2016

Using SQLite in express-session

I am trying to use sqlite with express.js session. I have this already working with the MsSQL, but need to do the same thing with the SQLite version.

In my app.js file I have following:

var session = require('express-session');
var SQLiteStore = require('connect-sqlite3')(session);

app.use(session({
    resave: true,
    //saveUninitialized: true,
    secret: "supersecret",
    store: new SQLiteStore(secrets.sqlite),
    cookie: { maxAge: 7 * 24 * 60 * 60 * 1000 } // 1 week
}));
...

Application boots ok, but when I go to my login page: It gives me the following error:

d:\H\v6\node_modules\express-session\session\store.js:77
var expires = sess.cookie.expires                         

TypeError: Cannot read property 'expires' of undefined
at SQLiteStore.Store.createSession (d:\H\v6\node_modules\express- 
session\session\store.js:77:28)
at d:\H\v6\node_modules\express-session\index.js:426:15
at Statement.<anonymous> (d:\H\v6\node_modules\connect-sqlite3\lib\connect-
sqlite3.js:104:17)

I also had some errors previously, but as I could see they were related to different column names in DB. For example the MSSQLStore has Sessions and Expires columns, while the SQLiteStore has Sess and Expired columns. I renamed the columns in the database, and that removed the unknown column error.

Aucun commentaire:

Enregistrer un commentaire