cookie와 session을 통해 로그인을 구현할 수 있게 됐다. 그러나 문제가 있다. session이 서버에 저장된다는 것이다.
즉, 서버를 다시 시작하면 session 정보가 사라진다는 뜻이다. 따라서 session을 서버가 아니라 DB에 저장해야 안전하다.
app.use(
session({
secret: "비밀",
resave: true,
saveUninitialized: false,
store: MongoStore.create({ mongoUrl: "mongodb://localhost/test" }),
})
);
Forces the session to be saved back to the session store, even if the session was never modified during the request.
true는 로그인할 때마다 session이 저장되는 것이고
false는 똑같은 session은 한 번만 저장하도록 한다.
Forces a session that is "uninitialized" to be saved to the store. A session is uninitialized when it is new but not modified.
true는 로그인 안된 상태에서도 session을 DB에 저장하고
false는 로그인이 된 상태에서만 session을 DB에 저장한다.