Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Unexpected token u in JSON at position 0 #134

Open
Ziirkov opened this issue May 11, 2022 · 3 comments
Open

SyntaxError: Unexpected token u in JSON at position 0 #134

Ziirkov opened this issue May 11, 2022 · 3 comments

Comments

@Ziirkov
Copy link

Ziirkov commented May 11, 2022

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

@mweibel
Copy link
Owner

mweibel commented Jun 8, 2022

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.

@Ziirkov
Copy link
Author

Ziirkov commented Jun 17, 2022

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

@mweibel
Copy link
Owner

mweibel commented Jul 18, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants