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

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

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