fix: logout session works now

This commit is contained in:
Mike 2025-03-31 20:15:14 -04:00
parent 4be0ea5870
commit 63656eb864
4 changed files with 22 additions and 18 deletions

View file

@ -5,14 +5,14 @@
"name": "KeyNotes.App",
"dependencies": {
"KeyNotes.App": ".",
"bcryptjs": "latest",
"connect-sqlite3": "latest",
"ejs": "latest",
"express": "latest",
"express-session": "latest",
"express-validator": "latest",
"passport": "latest",
"passport-local": "latest",
"bcryptjs": "^3.0.2",
"connect-sqlite3": "^0.9.15",
"ejs": "^3.1.10",
"express": "^4.21.2",
"express-session": "^1.18.1",
"express-validator": "^7.2.1",
"passport": "^0.7.0",
"passport-local": "^1.0.0",
},
},
},

View file

@ -20,7 +20,7 @@ app.use(
session({
store: new SQLiteStore({ dir: "./src/db/", db: "keynotes.db" }),
secret: "keynotes",
cookie: { maxAge: 7 * 24 * 60 * 60 * 1000, sameSite: "strict" },
cookie: { maxAge: 7 * 24 * 60 * 60 * 1000 },
saveUninitialized: false,
resave: false,
}),

View file

@ -3,11 +3,9 @@ const db = require("../models/query");
const { validationResult } = require("express-validator");
function loginGet(req, res, next) {
console.log(req.user, req.session.cookie);
console.table(req.session);
if (!req.user && req.session.id) {
req.session.id = null;
}
// if (!req.user && req.session.id) {
// req.session.id = null;
// }
res.render("login", {
pageTitle: "InspiredCliches | Login",
errors: req.session.messages,
@ -15,11 +13,18 @@ function loginGet(req, res, next) {
}
function logOut(req, res, next) {
res.clearCookie("connect.sid", { path: "/" });
req.logout((err) => {
if (err) return next(err);
if (err) {
return next(err);
}
req.session.destroy((err) => {
if (err) {
return next(err);
}
res.clearCookie("connect.sid"); // Clear the session cookie
res.redirect("/");
});
});
res.redirect("/");
}
function signUpGet(req, res, next) {

View file

@ -32,7 +32,6 @@ function addLike(req, res) {
function addNotePost(req, res) {
const { message, media } = req.body;
console.log("add note post");
if (res.locals.currentUser) {
const userId = res.locals.currentUser.user_id;