11import 'dart:convert' ;
2+ import 'dart:async' ;
23import 'dart:io' ;
34
45import 'package:dart_frog/dart_frog.dart' ;
@@ -23,6 +24,9 @@ import 'package:ht_email_repository/ht_email_repository.dart';
2324import 'package:ht_shared/ht_shared.dart' ;
2425import 'package:uuid/uuid.dart' ;
2526
27+ // Assuming a fixed ID for the AppConfig document
28+ const String _appConfigId = 'app_config' ;
29+
2630// --- Request ID Wrapper ---
2731
2832/// {@template request_id}
@@ -247,6 +251,20 @@ HtDataRepository<SuggestedContentTemplate>
247251 return HtDataRepository <SuggestedContentTemplate >(dataClient: client);
248252}
249253
254+ /// Middleware to asynchronously load and provide the AppConfig.
255+ Middleware _appConfigProviderMiddleware () {
256+ return (handler) {
257+ return (context) async {
258+ // Read the AppConfigRepository from the context
259+ final appConfigRepository = context.read <HtDataRepository <AppConfig >>();
260+ // Read the AppConfig instance
261+ final appConfig = await appConfigRepository.read (id: _appConfigId);
262+ // Provide the AppConfig instance to downstream handlers/middleware
263+ return handler (context.provide <AppConfig >(() => appConfig));
264+ };
265+ };
266+ }
267+
250268// --- Middleware Definition ---
251269Handler middleware (Handler handler) {
252270 // Initialize repositories when middleware is first created
@@ -341,6 +359,8 @@ Handler middleware(Handler handler) {
341359 // (or early in the "response" phase) to catch errors from upstream.
342360 // ==========================================================================
343361 return handler
362+ // Add the asynchronous AppConfig provider middleware here
363+ .use (_appConfigProviderMiddleware ())
344364 // --- 1. Request ID Provider (Early Setup) ---
345365 // PURPOSE: Generates a unique ID (UUID v4) for each incoming request.
346366 // Provides `RequestId` instance via context.
@@ -410,6 +430,7 @@ Handler middleware(Handler handler) {
410430 ),
411431 )
412432
433+
413434 // --- 4. Authentication Service Providers (Auth Logic Dependencies) ---
414435 // PURPOSE: Provide the core services needed for authentication logic.
415436 // ORDER: These MUST be provided BEFORE `authenticationProvider` and
0 commit comments