Hi im having problem with express-session, it seems like not saving my user session. Here is when I declare my session
//Session
//app.use(express.urlencoded({extended: true}))
app.use(session({
secret: "key per i cookie",
saveUninitialized: false,
resave: false,
store: MongoStore.create({
mongoUrl: process.env.URI,
autoRemove: 'disabled'
}),
cookie: { maxAge:30000,secure:false }
}))
app.use(cookieParser());
app.use(function(req, res, next){
res.locals.session = req.session.user
next()
})
And then saving it when user is logged in
app.post('/login', async(req,res) =>{
const { username, password } = req.body
const user = await User.findOne({username}).lean()
if(!user){
return res.json({status:'error', error:'Username o password non validi'})
}
if(await bcrypt.compare(password, user.password)){
const token = jwt.sign({
id: user._id,
username: user.username
},
JWT_SECRET
)
req.session.user = username
req.session.save()
console.log('Utente loggato ' + req.session.user)
return res.json({status:'ok', data: token})
}
res.json({status:'error',error:'Username o password non validi'})
})
Apparently in the post I save the session but after login, when trying to access in an EJB page with
<% if(session.user) { %>
<h1>Session stored</h1>
<% } else { %>
<p>No session</p>
<% }%>
I got no session stored. What im doing wrong?? Thanks in advance
How to prevent a token created with OAuth 2.0 from expiring?
i have a revslider and want to have a long-from-top but it still looks like a short-from-top
Want to improve this question? Update the question so it's on-topic for Stack Overflow
First I am trying to go to this link: driverget("https://www
First I'm gonna try to explain a few things and be more explicit so that I can point out what my real problem is