Полагаю, заголовок довольно понятен. Дело в том, что я не могу выйти из браузера. Cookies не удаляются при выходе из системы. Если я удаляю cookie вручную и перезагружаю страницу, то пользователь снова входит в систему и создает новый cookie. Однако, когда я выхожу из почты, это работает. Если я выйду из системы, пользователь не сможет увидеть ресурсы.
Вот мой логин и выход из системы
exports.login = (req, res, next) => {
passport.authenticate("local", (err, user, failureDetails) => {
if (err) {
res
.status(500)
.json({ message: "Something went wrong authenticating user" });
return;
}
if (!user) {
// "failureDetails" contains the error messages
// from logic in "LocalStrategy" { message: '...' }.
res.status(401).json(failureDetails);
return;
}
// save user in session
req.login(user, err => {
if (err) {
res.status(500).json({ message: "Session save went bad." });
return;
}
// We are now logged in (that's why we can also send req.user)
return res.json({ user });
});
})(req, res, next);
}
exports.logout = function (req, res, next) {
// Here I've tried with req.session.destroy(), clearCookies() etc...
req.logout()
res.status(200).json({ message: "Log out success!" });
}
Здесь соответствующая часть файла app.js
app.use(session({
secret: "some secret goes here",
resave: false, //I tried with false
saveUninitialized: false, // I tried with false
store: new MongoStore({ mongooseConnection: mongoose.connection
})
}));
Auth Routes
const auth_controller = require('../../controllers/authController');
router.post('/register', auth_controller.register);
router.post('/login', auth_controller.login);
router.post('/logout', auth_controller.logout);
router.get('/loggedin', auth_controller.loggedIn);
router.get('/get-user', auth_controller.getUser);
Я видел некоторые темы по этой проблеме здесь, но ни одна из них не решила мою проблему. Заранее спасибо!