Session is created when a browser first reachs to a backend. And browser only gets the sessionID. Problem is that the default server-side session storage is a MoemoryStore. Means it is volatile. It will perish whenever the backend restart or the server dies. (Not designed for a product environment)
more info
Saves the session in the mongoDB.
npm i connect-mongo
import MongoStore from "connect-mongo";
app.use(session({
secret: "Hello",
resave: true,
saveUninitialized: true,
store: MongoStore.create({mongoUrl: "mongodb://127.0.0.1:27017/youtubeclone"}),
})
);