const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
const require_utils_auth_getAuth = require('../utils/auth/getAuth.cjs');
let better_auth_node = require("better-auth/node");
better_auth_node = require_rolldown_runtime.__toESM(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: (0, better_auth_node.fromNodeHeaders)(req.headers) });
	if (session) {
		const formattedSession = require_utils_auth_getAuth.formatSession(session);
		res.locals.authType = "session";
		Object.entries(formattedSession).forEach(([key, value]) => {
			res.locals[key] = value;
		});
		return next();
	}
	next();
};

//#endregion
exports.authMiddleware = authMiddleware;
//# sourceMappingURL=sessionAuth.middleware.cjs.map