我正在尝试使用护照验证我的会话。套接字: npm passport socket.io doc
我试图遵循npm文档:
在我的前端:
verify = () => {
let socket = null;
var token = sessionStorage.getItem('token');
socket = io.connect('http://localhost:8080', {
query: {token: token}
});
}
我的后端:
let io = require('socket.io')(server);
app.set("io", io);
io.use(passportSocketIo.authorize({
secret: config.jwt.secret,
success: onAuthorizeSuccess, // *optional* callback on success
fail: onAuthorizeFail, // the session_secret to parse the cookie
}));
function onAuthorizeSuccess(data, accept){
console.log('successful connection to socket.io');
accept(null, true);
accept();
}
function onAuthorizeFail(data, message, error, accept){
if(error)
throw new Error(message);
console.log('failed connection to socket.io:', message);
}
我得到这个错误:
auth.store.get(data.sessionID, function(err, session){
^
TypeError: Cannot read property 'get' of null