import { Request } from "express"; import { getUserSession } from "../utils/utils"; export async function sessionProtection(req: Request, res: any, next: any) { const session = await getUserSession(req); if (!session) { return res.status(401).send({ err: "unauthorized" }); } // check if session is expired if (session.expires < new Date()) { return res.status(401).send({ err: "unauthorized" }); } next(); }