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

121
Views
session not saved after running on the browser

session not saved after running on the browser if we do that on the postman the session well be saved after login and logout but after i logedin in the browser and logout i"ll receive the default session not the session i"ll passed

userApi.js

router.post('/login', async function (request, response) {
console.log(request.body)
const user=request.body
let userFound=await User.find({$or:[{phoneNumber:user.emailPhoneNumber},
    {email: user.emailPhoneNumber,password:user.password}]}).exec();

if(userFound.length!=0){
    request.session.login=true
    request.session.save()
    response.send("success")
}
response.send("user not found")

});

router.get('/logout',async function (request, response){
console.log(request.session)
request.session.destroy()
})

connect to server

 logIn(user) {
    axios.post(`http://localhost:5500/login`,user);
}
  logout(){
 axios.get(`http://localhost:5500/logout`);
}

server.js

  app.use(
 session({
 secret: crypto.randomBytes(16).toString("hex"),
store: new MemoryStore(),
resave: false,
saveUninitialized: true,
cookie: {
  secure: false,
  maxAge: 24*60*60*1000}
})
);

login.js

const [userFound,setUserFound]=useState({});

const onFinish = async (values) => {
    console.log(values)
    let connectToServer=new ConnectToServer();
    connectToServer.logIn(values);
    let userFound1=await 
    connectToServer.getUserByEmailPhoneNumber(values.emailPhoneNumber)
    if(userFound1.length<1)
      {
        alert("user dosent found try again")
        return;
      }
    setUserFound(userFound1.data)
};

student.js the student have the logout button

const logoutfunc=()=>{
 let connect=new connectToServer();
 connect.logout();
 setclickLogout(true);
}
return (
 <div>
     <button onClick={()=>logoutfunc()}>logout</button>
     {clickLogout?<Redirect to={`/`}/>:null}
 </div>
)
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!