Files
lst_v3/backend/middleware/auth.middleware.ts
2026-02-20 11:05:03 -06:00

31 lines
798 B
TypeScript

import { fromNodeHeaders } from "better-auth/node";
import type { NextFunction, Request, Response } from "express";
import { auth } from "../utils/auth.utils.js";
export const requireAuth = async (
req: Request,
res: Response,
next: NextFunction,
) => {
// TODO: add the real auth stuff in later.
try {
const session = await auth.api.getSession({
headers: fromNodeHeaders(req.headers),
});
if (!session) {
//return res.status(401).json({ error: "Unauthorized" });
console.info("not auth of course");
}
// attach session to request for later use
(req as any).session = session;
console.info(
"Just passing the middleware and reminder that we need to add the real stuff in.",
);
next();
} catch {
return res.status(401).json({ error: "Unauthorized" });
}
};