0

I am using passportjs, express 4, socket.io and to connect passportjs with socket i have added the passport.socketio with connect-mongo as Session Store. I saw in many posts that i have to avoid cors use. So when i use in client side code: io.connect('/');, none of functions is called(success/fail). When i use io.connect('http://localhost:8565');, fail function get called with Message: "No session found". Store:

var store = new (require("connect-mongo")(session))({url: "mongodb://localhost/databaseName"});

Session:

var sessionMiddleware = session({
  key: 'your.sid-key',
  secret: 'reallyawesomesecret',
  resave: false,
  saveUninitialized: true,
  cookie: { maxAge: (365 * 24 * 60 * 60) },
  rolling: true,
  store: store
});

Passport.socketio:

io.use(passportSocketIo.authorize({
  cookieParser: cookieParser,
  key: 'your.sid-key',
  secret: 'reallyawesomesecret',
  store: store,
  success: onAuthorizeSuccess,
  fail: onAuthorizeFail
}));

Do i have to do something with the "key:'your.sid-key'," ? or i miss something else? Inside function failed error get value false and data.isAuthenticated() is true, but data.user have {logged_in: false}.

Honchar Denys
  • 1,408
  • 4
  • 29
  • 54
  • possible duplicate of [Passport.socketio has issues finding session](http://stackoverflow.com/questions/25456656/passport-socketio-has-issues-finding-session) – Honchar Denys Mar 23 '15 at 11:02

1 Answers1

0

Actually the problem was in different place, on the client side code, i setup the socket with url localhost:port, when i change it to 127.0.0.1:port it worked out.

Honchar Denys
  • 1,408
  • 4
  • 29
  • 54