This is a small example application generated with the Express application generator.
The tl;dr; on how to use iron-session
with Express is this:
import { ironSession } from "iron-session/express";
const session = ironSession({
cookieName: "iron-session/examples/express",
password: process.env.SECRET_COOKIE_PASSWORD,
cookieOptions: {
secure: process.env.NODE_ENV === "production",
},
});
router.get("/profile", session, async function (req, res) {
// now you can access all of the req.session.* utilities
if (req.session.user === undefined) {
res.redirect("/restricted");
return;
}
res.render("profile", {
title: "Profile",
userId: req.session.user.id,
});
});