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" }); } };