I am working on angular and nodejs and their libraries, passport, passport-local, express, express-session. the req.logIn () does not save the data to the session, I tried the rest api with postman and it works correctly, and it saves the data, what is happening ?. could someone help please thank you in advance?
this is the code that according to passport closes the session:
app.get('/logout', (req, res) => {
req.logout();
res.redirect('logout');
});
add cors handling to be able to communicate with another port and activate the credentials for sending the cookie:
app.use(cors({origin:["http://localhost:4200"],credentials:true}));
const store = new session.MemoryStore; *//session configuration*
app.use(session({
secret:"SECRET",
resave:true,
saveUninitialized:true,
cookie:{
secure: false
},
store:store
}))
app.use(passport.initialize());*//initialize passport and passport sessions*
app.use(passport.session());
the login part is like this:
exports.Login = (req, res, next) => {
passport.authenticate('local', (err, usuario, info) => {
if (err) {
next(err)
}
if (!usuario) {
res.json(info)
}
else {
req.logIn(usuario, (err) => {
if (err) {
next(err)
}
else {
res.json("usuario existente"})
next()
}
})
}
})(req,res, next)
}
question from:
https://stackoverflow.com/questions/65890437/why-req-login-doesnt-store-data-when-using-angular 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…