Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!