1
1
import 'dart:convert' ;
2
+ import 'dart:async' ;
2
3
import 'dart:io' ;
3
4
4
5
import 'package:dart_frog/dart_frog.dart' ;
@@ -23,6 +24,9 @@ import 'package:ht_email_repository/ht_email_repository.dart';
23
24
import 'package:ht_shared/ht_shared.dart' ;
24
25
import 'package:uuid/uuid.dart' ;
25
26
27
+ // Assuming a fixed ID for the AppConfig document
28
+ const String _appConfigId = 'app_config' ;
29
+
26
30
// --- Request ID Wrapper ---
27
31
28
32
/// {@template request_id}
@@ -247,6 +251,20 @@ HtDataRepository<SuggestedContentTemplate>
247
251
return HtDataRepository <SuggestedContentTemplate >(dataClient: client);
248
252
}
249
253
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
+
250
268
// --- Middleware Definition ---
251
269
Handler middleware (Handler handler) {
252
270
// Initialize repositories when middleware is first created
@@ -341,6 +359,8 @@ Handler middleware(Handler handler) {
341
359
// (or early in the "response" phase) to catch errors from upstream.
342
360
// ==========================================================================
343
361
return handler
362
+ // Add the asynchronous AppConfig provider middleware here
363
+ .use (_appConfigProviderMiddleware ())
344
364
// --- 1. Request ID Provider (Early Setup) ---
345
365
// PURPOSE: Generates a unique ID (UUID v4) for each incoming request.
346
366
// Provides `RequestId` instance via context.
@@ -410,6 +430,7 @@ Handler middleware(Handler handler) {
410
430
),
411
431
)
412
432
433
+
413
434
// --- 4. Authentication Service Providers (Auth Logic Dependencies) ---
414
435
// PURPOSE: Provide the core services needed for authentication logic.
415
436
// ORDER: These MUST be provided BEFORE `authenticationProvider` and
0 commit comments