import { formatSession } from "../utils/auth/getAuth.mjs";
import { fromNodeHeaders } from "better-auth/node";

//#region src/middlewares/sessionAuth.middleware.ts
const authMiddleware = (auth) => async (req, res, next) => {
	if (typeof res.locals.authType !== "undefined") return next();
	const session = await auth.api.getSession({ headers: fromNodeHeaders(req.headers) });
	if (session) {
		const formattedSession = formatSession(session);
		res.locals.authType = "session";
		Object.entries(formattedSession).forEach(([key, value]) => {
			res.locals[key] = value;
		});
		return next();
	}
	next();
};

//#endregion
export { authMiddleware };
//# sourceMappingURL=sessionAuth.middleware.mjs.map