Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
sessionStorage returns null

I have this post method where I have the variable username,variable whose content I need to use it in another js file.In this method I use sessionStorage.setItem().

app.post('/auth', function(request, response) {
   var username = request.body.username;
   var password = request.body.password;

   sessionStorage.setItem('user', JSON.stringify(username));

   if (username && password) {
       connection.query('SELECT * FROM usuarios WHERE nombre_usuario = ? AND password_usuario = ?', [username, password], function(error, results, fields) {
           if (results.length > 0) {
               request.session.loggedin = true;
               request.session.username = username;
               response.redirect('/home');
           } else {
               response.send('Incorrect Username and/or Password!');
           }
           response.end();
       });
   } else {
       response.send('Please enter Username and Password!');
       response.end();
   }
});

Then, as I have said I need the username variable in another js file. For that I use sessionStorage.getItem(), but always returns null.

 case "based":
           
            // INSERT INTO BD states, Q and type of automaton, M

            console.log("the username is " + sessionStorage.getItem('user'));

            var state = this.chart.obtainStates();
            console.log ("the state is " + state);

            var state2 = state.split("x",1);
            console.log ("the state2 is " + state2);
       }
    
  }

What should I do?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda