Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

No session found - MySQL store #114

Open
przemko0 opened this issue Mar 12, 2016 · 2 comments
Open

No session found - MySQL store #114

przemko0 opened this issue Mar 12, 2016 · 2 comments

Comments

@przemko0
Copy link

Hello, I've got an issue that I've been trying trying to fix since few days. So the passport.socketio keeps telling me failed connection to socket.io. No session found There is the code :

var express = require('express');
var session = require('express-session');
var MySQLStore = require('express-mysql-session')(session);
var passportSocketIo = require("passport.socketio");
var session = require('express-session');
var cookieParser = require('cookie-parser');

var sessionStore = new MySQLStore({
    checkExpirationInterval: 900000,// How frequently expired sessions will be cleared; milliseconds.
    expiration: 86400000,// The maximum age of a valid session; milliseconds.
    createDatabaseTable: true,// Whether or not to create the sessions database table, if one does not already exist.
    schema: {
        tableName: 'sessions',
        columnNames: {
            session_id: 'session_id',
            expires: 'expires',
            data: 'data'
        }
    }
}, mysqlConnection);



var app = express();

app.use(cookieParser());
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use('/public', express.static('public'));

var sessionMiddleware = app.use(session({
    secret: 'your secret',
    name: 'name of session id',
    resave: true,
    saveUninitialized: true,
    store:sessionStore}));


app.use(passport.initialize());
app.use(passport.session());

passport.serializeUser(function(user, done) {
  done(null, user);
});
passport.deserializeUser(function(obj, done) {
  done(null, obj);
});
passport.use(new SteamStrategy({
    returnURL: domain+'auth/steam/return',
    realm: domain,
    apiKey: apiKey
  },
  function(identifier, profile, done) {
    process.nextTick(function () {
      profile.identifier = identifier;
      return done(null, profile);
    });
  }
));


app.get('/logout', function(req, res){
  req.logout();
  res.redirect('/');
});

app.get('/auth/steam',
  passport.authenticate('steam', { failureRedirect: '/' }),
  function(req, res) {
    res.redirect('/');
  });


var server = app.listen(80);
var io = require('socket.io')(server);

function onAuthorizeSuccess(data, accept){
  console.log('successful connection to socket.io');
  accept();
}

function onAuthorizeFail(data, message, error, accept){
  console.log('failed connection to socket.io:', message);
  accept();
}

io.use(passportSocketIo.authorize({
    cookieParser: cookieParser,       // the same middleware you registrer in express
    key:          'express.sid',       // the name of the cookie where express/connect stores its session_id
    secret:       'session_secret',    // the session_secret to parse the cookie
    store:        sessionStore,     // we NEED to use a sessionstore. no memorystore please
    success:     onAuthorizeSuccess,  // *optional* callback on success - read more below
    fail:        onAuthorizeFail
}));

io.on('connection', function(socket) {
    console.log(socket.request.user);
});
@cliedelt
Copy link

Same here. Did u find a solution?

@franckstifler
Copy link

You should replace express.sid with connect.id

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

No branches or pull requests

3 participants