mweibel / connect-session-sequelize

Sequelize SessionStore for Express/Connect

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SyntaxError: Unexpected token u in JSON at position 0

Ziirkov opened this issue · comments

Hi,

I'm trying to use connect-session-sequelize to store the session on a mssql server.

The insert works fine, the session id is stored in my database but when i refresh my page to see if I still got the same session i keep getting this error :
image

Here is my server.js :

const express = require('express');
const app = express();
const port = process.env.PORT || 8000
const db = require('../config/DBconfig')
const Session = require('../repository/models/Sessions')

require('dotenv').config()

const cookieParser = require('cookie-parser');
const session = require('express-session')
const SequelizeStore = require("connect-session-sequelize")(session.Store);

db.authenticate().then(() => console.log('Database Connected !')).catch( err => console.log(err))

app.use(express.json());
app.use(express.urlencoded());

app.use(cookieParser()); 

const store = new SequelizeStore({
    db: db,
    table:"sessions",
    checkExpirationInterval: 24 * 60 * 60 * 1000,
    expiration: 14 * 86400,
})

app.use(session({
    secret: process.env.SECRET,
    resave: false,
    store: store,
    saveUninitialized: false,
    cookie: { maxAge: 1000 * 60 * 60 * 24, secure: false, httpOnly: true },
}))

module.exports = {
    app,
    port
}

I went through and did a console.log(session.data) in the npm package, turns out session.data is undefined :
image

Do you have any idea where this is error is coming from / what i did wrong ?

Feel free to ask for additional code if you need to.

Regards,
Jordan

hi,

there's an example repo (documented in the README) which should be used to submit issues: https://github.com/mweibel/connect-session-sequelize-example

Please add a reproduction case with an example repository forked from my repository.

I haven't yet found this issue so I'm not sure what the issue could be, TBH.

Hi,

I used the repository you gave me in your reply and it works fine (Cookie is saved in database) however, in my project it was still not working even after copy/pasting all the code in the example.

Turns out i was using the latest version of the package and in your example the version in the package.json is 7.0.0.

I don't know if there are syntax changes that I did not understand or if the package doest not support old MSSQL versions anymore (It might come from our MSSQL which is a 2012).

I will use the 7.0.0 version for now since it works smoothly with latest versions of other packages.

Let me know if you need more informations if you try to investigate that issue, i would be glad to help. :)

Thanks a lot for your help !

Regards,
Jordan Leston

@Ziirkov I upgraded to latest versions of all deps and still get no errors. Could you please check again? Is it a mssql specific thing? If yes please try to figure out why that exactly happens and provide a PR to fix it. I don't have access to an mssql instance.