Express-Session with MySQLStore not persisting sessions in MySQL database

I am using express-session and express-mysql-session to manage sessions in my Node.js application with a MySQL database. While the session store initializes successfully and a sessions table is created in the database, the session data is not being stored. When I log in, the session ID is generated, but the session store remains undefined, and no data is written to the sessions table.

Code:
sessionStore.js

import expressMySQLSession from "express-mysql-session";
import session from "express-session";
import { pool } from "../../app.mjs";

// Configure session store using express-mysql-session
//const MySQLStore = expressMySQLSession(session); // dont know if needed

let sessionStore; // Define sessionStore variable outside the asynchronous context so it can be exported

async () => {
  try {
    const poolInstance = await pool; // Await the pool promise to resolve
    sessionStore = new expressMySQLSession(
      {
        createDatabaseTable: true,
        expiration: 1000 * 60 * 60 * 1, // Session expiration time in milliseconds (1 hour)
      },
      poolInstance
    );
    console.log("Session store initialized successfully");
  } catch (err) {
    console.error("Error initializing session store:", err);
  }
};

export default sessionStore;

app.mjs

import express, { response } from "express";
import dotenv from "dotenv";
dotenv.config();
import mysql from "mysql2";
import cookieParser from "cookie-parser";
import session from "express-session";
import passport from "passport";
import "./src/strategies/local.js";
import sessionStore from "./src/utils/sessionStore.js";

const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
const pool = mysql
  .createPool({
    connectionLimit: 10,
    host: process.env.HOST,
    user: process.env.USER,
    password: process.env.PASSWORD,
    database: process.env.DATABASE,
  })
  .promise();

export { pool };

app.use(
  session({
    secret: "KTSJSRIJTHRSTIOJHSR",
    resave: false,
    saveUninitialized: false,
    store: sessionStore,
    rolling: true, // Refresh the session cookie on every request to extend session lifetime
    expires: new Date(Date.now() + 1000 * 60 * 60 * 3), // Expires session after 3 hours of total duration
    cookie: {
      maxAge: 1000 * 60 * 60 * 1, // expire session after 1 hour in milliseconds (for client-side)
      sameSite: "strict",
    },
  })
);
app.use(passport.initialize());
app.use(passport.session());


app.use((request, response, next) => {
  console.log("Inside auth check");
  console.log(request.user);
  console.log("Session store:", JSON.stringify(sessionStore, null, 2));
  console.log("Session ID:", request.sessionID); // Log the session ID
  if (request.user) {
    next();
  } else {
    response.sendStatus(401); // Unauthorized status if user is not authenticated
  }
});

here are the versions if it is useful:
“express”: “^4.19.2”,
“express-mysql-session”: “^2.1.8”,
“mysql2”: “^3.10.1”,
“passport”: “^0.7.0”,
“passport-local”: “^1.0.0”
“express-session”: “^1.18.0”

What I Tried:
Verified that the sessions table is created in the database.
Checked the session ID is being generated.
Printed the sessionStore to console, which remains undefined.
Expected Outcome:
The session data should be persisted in the MySQL sessions table.

Please review my question and provide guidance on what might be causing the session data not to be stored in the MySQL database and how to resolve this issue.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật