how to prevent logging out user from refreshing the page in express js

so i use express sessions and reactjs for frontend . when i log in the session is set username correctly and can access on other routes as well but once i hit refresh the user log outs , how to prevent this ?
app.use(sessions({
secret: process.env.SECRET_KEY,
resave: false,
saveUninitialized: false,
cookie: {
secure: false,
httpOnly: false,
maxAge: 1000 * 60 * 60 * 24
}
}))

routes.get('/login',LoginController)
routes.get('/orders',OrderPage)

app.use(sessions({
secret: process.env.SECRET_KEY,
resave: false,
saveUninitialized: false,
cookie: {
secure: false,
httpOnly: false,
maxAge: 1000 * 60 * 60 * 24
}
}))

routes.get('/login',LoginController)
routes.get('/orders',OrderPage)

LoginController.js
if(password===123){
req.session.name = username;
}
if(password===123){
req.session.name = username;
}
OrderPage.js
const name = req.session.name;
console.log(name) //Logs the name
const name = req.session.name;
console.log(name) //Logs the name
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server