* Referenceerror: Session is not defined *

Asked

Viewed 111 times

0

I’m having a problem, sharing the Express cookie user data and session functions! the goal is to store such data in my Socket.IO, but it presents a reference error problem where it says the session is not set. I have little knowledge about it, I would like to know how and where I will name this session?


Excerpt from the code where the error points : const currentSession = Session[sessionid]

//Verificado de regra
io.use((socket,next) =>{
    const cookieData = socket.request.headers.cookie;
    const cookieObj = cookie.parse(cookieData);//Gera um objeto com dados do cookie
    const  sessionHash = cookieObj[config.sessionKey] ||'';// Acessa o hash da sessão 
    const sessionID = sessionHash.split('.')[0].slice(2);
    store.all((err,sessions)=>{
        const currentSession = session[sessionID]; // referenciar a sessão ID
        if( err|| !currentSession){
            return next(new Error('Acesso Negado!'));
        }
        socket.handshake.session = currentSession;
        return next();
    })
})

1 answer

1


tries to put Sessions instead of Session, Sessions is being passed as parameter

store.all((err,sessions)=>{
      const currentSession = sessions[sessionID]; // referenciar a sessão ID
  • My God! What a shame, that was it kkkkkkk Sorry, it was worth obg!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.