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", "name": "KeyNotes.App",
"dependencies": { "dependencies": {
"KeyNotes.App": ".", "KeyNotes.App": ".",
"bcryptjs": "latest", "bcryptjs": "^3.0.2",
"connect-sqlite3": "latest", "connect-sqlite3": "^0.9.15",
"ejs": "latest", "ejs": "^3.1.10",
"express": "latest", "express": "^4.21.2",
"express-session": "latest", "express-session": "^1.18.1",
"express-validator": "latest", "express-validator": "^7.2.1",
"passport": "latest", "passport": "^0.7.0",
"passport-local": "latest", "passport-local": "^1.0.0",
}, },
}, },
}, },

View file

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

View file

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

View file

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