I've recently implemented passport.js for authentication onto my express server. I'm trying to leverage this authentication for my socket.io server as well. So I'm trying to use the passport.socketio package to do this.
I'm using it as such:
io.use(async (socket, next) => {
console.log("pre auth")
await passportSocketIo.authorize({
cookieParser: cookieParser, // the same middleware you registrer in express
key: 'auth', // the name of the cookie where express/connect stores its session_id
secret: 'keyboard cat', // the session_secret to parse the cookie
store: tediousConfig, // we NEED to use a sessionstore. no memorystore please
success: onAuthorizeSuccess, // *optional* callback on success - read more below
fail: onAuthorizeFail, // *optional* callback on fail/error - read more below
})
console.log("post auth")
}
With the success and fail callbacks being:
function onAuthorizeSuccess(data, accept){
console.log("Success connection to socket.io");
accept();
}
function onAuthorizeFail(data, message, error, accept){
if(error)
throw new Error(message);
console.log("failed connection to web socket", message);
}
However, when I try to connect I get both the console messages of "pre auth" and "post auth" but no message from the authorize function, and no error messages at all.
Any help would be gratefully received!