Skip to content

Commit 035d8cd

Browse files
committed
refactor: Integrate auth token into HTTP client
- Use token from auth repository - Pass storage to auth repo
1 parent 77dbc5a commit 035d8cd

File tree

3 files changed

+41
-37
lines changed

3 files changed

+41
-37
lines changed

lib/headlines-feed/bloc/headlines_feed_bloc.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
7979
.whereType<Country>()
8080
.map((c) => c.isoCode)
8181
.toList(),
82-
}, limit: _headlinesFetchLimit,);
82+
}, limit: _headlinesFetchLimit);
8383
emit(
8484
HeadlinesFeedLoaded(
8585
headlines: response.items,
@@ -254,7 +254,7 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
254254
.whereType<Country>()
255255
.map((c) => c.isoCode)
256256
.toList(),
257-
}, limit: _headlinesFetchLimit,);
257+
}, limit: _headlinesFetchLimit);
258258
emit(
259259
HeadlinesFeedLoaded(
260260
headlines: response.items, // Replace headlines on refresh

lib/main.dart

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_bloc/flutter_bloc.dart';
3-
import 'package:ht_auth_api/ht_auth_api.dart'; // Concrete Auth Client Impl
4-
import 'package:ht_auth_repository/ht_auth_repository.dart'; // Auth Repository
5-
import 'package:ht_data_api/ht_data_api.dart'; // Concrete Data Client Impl
6-
import 'package:ht_data_repository/ht_data_repository.dart'; // Data Repository
7-
import 'package:ht_http_client/ht_http_client.dart'; // HTTP Client
8-
import 'package:ht_kv_storage_shared_preferences/ht_kv_storage_shared_preferences.dart'; // KV Storage Impl
9-
import 'package:ht_main/app/app.dart'; // The App widget
10-
import 'package:ht_main/bloc_observer.dart'; // App Bloc Observer
11-
import 'package:ht_shared/ht_shared.dart'; // Shared models, FromJson, ToJson, etc.
3+
import 'package:ht_auth_api/ht_auth_api.dart';
4+
import 'package:ht_auth_repository/ht_auth_repository.dart';
5+
import 'package:ht_data_api/ht_data_api.dart';
6+
import 'package:ht_data_repository/ht_data_repository.dart';
7+
import 'package:ht_http_client/ht_http_client.dart';
8+
import 'package:ht_kv_storage_shared_preferences/ht_kv_storage_shared_preferences.dart';
9+
import 'package:ht_main/app/app.dart';
10+
import 'package:ht_main/bloc_observer.dart';
11+
import 'package:ht_shared/ht_shared.dart';
1212

1313
void main() async {
1414
WidgetsFlutterBinding.ensureInitialized();
@@ -23,23 +23,13 @@ void main() async {
2323
late final HtAuthRepository authenticationRepository;
2424

2525
// 3. Define Token Provider
26-
// TODO(refactor): This is a temporary workaround. The HtAuthRepository
27-
// should be refactored to provide a public method/getter to retrieve
28-
// the current authentication token string. This function should then
29-
// call that method.
3026
Future<String?> tokenProvider() async {
31-
// For now, return null as we don't have a way to get the token
32-
// from the current HtAuthRepository implementation.
33-
// The HtHttpClient will make unauthenticated requests by default.
34-
// The authentication flow will handle obtaining and storing the token
35-
// via the HtAuthRepository's signIn/verify methods.
36-
// A future refactor is needed to make the token available here.
37-
return null;
27+
return authenticationRepository.getAuthToken();
3828
}
3929

4030
// 4. Instantiate HTTP Client
4131
final httpClient = HtHttpClient(
42-
baseUrl: 'http://localhost:8080', // Provided base URL for Dart Frog backend
32+
baseUrl: 'http://localhost:8080',
4333
tokenProvider: tokenProvider,
4434
);
4535

@@ -49,8 +39,7 @@ void main() async {
4939
// Initialize the authenticationRepository instance
5040
authenticationRepository = HtAuthRepository(
5141
authClient: authClient,
52-
// storageService is not a parameter based on errors.
53-
// Token persistence must be handled within HtAuthRepository using HtKVStorageService internally.
42+
storageService: kvStorage,
5443
);
5544

5645
// 6. Instantiate Data Clients and Repositories for each model type
@@ -59,7 +48,7 @@ void main() async {
5948

6049
final headlinesClient = HtDataApi<Headline>(
6150
httpClient: httpClient,
62-
modelName: 'headline', // Assuming 'headline' is the model name for the API
51+
modelName: 'headline',
6352
fromJson: Headline.fromJson,
6453
toJson: (headline) => headline.toJson(),
6554
);
@@ -69,7 +58,7 @@ void main() async {
6958

7059
final categoriesClient = HtDataApi<Category>(
7160
httpClient: httpClient,
72-
modelName: 'category', // Assuming 'category' is the model name for the API
61+
modelName: 'category',
7362
fromJson: Category.fromJson,
7463
toJson: (category) => category.toJson(),
7564
);
@@ -79,7 +68,7 @@ void main() async {
7968

8069
final countriesClient = HtDataApi<Country>(
8170
httpClient: httpClient,
82-
modelName: 'country', // Assuming 'country' is the model name for the API
71+
modelName: 'country',
8372
fromJson: Country.fromJson,
8473
toJson: (country) => country.toJson(),
8574
);
@@ -89,15 +78,15 @@ void main() async {
8978

9079
final sourcesClient = HtDataApi<Source>(
9180
httpClient: httpClient,
92-
modelName: 'source', // Assuming 'source' is the model name for the API
81+
modelName: 'source',
9382
fromJson: Source.fromJson,
9483
toJson: (source) => source.toJson(),
9584
);
9685
final sourcesRepository = HtDataRepository<Source>(dataClient: sourcesClient);
9786

9887
final userContentPreferencesClient = HtDataApi<UserContentPreferences>(
9988
httpClient: httpClient,
100-
modelName: 'user_content_preferences', // Assuming model name
89+
modelName: 'user_content_preferences',
10190
fromJson: UserContentPreferences.fromJson,
10291
toJson: (prefs) => prefs.toJson(),
10392
);
@@ -108,18 +97,17 @@ void main() async {
10897

10998
final userAppSettingsClient = HtDataApi<UserAppSettings>(
11099
httpClient: httpClient,
111-
modelName: 'user_app_settings', // Assuming model name
100+
modelName: 'user_app_settings',
112101
fromJson: UserAppSettings.fromJson,
113102
toJson: (settings) => settings.toJson(),
114103
);
115104
final userAppSettingsRepository = HtDataRepository<UserAppSettings>(
116105
dataClient: userAppSettingsClient,
117106
);
118107

119-
// Assuming AppConfig model exists in ht_shared and has fromJson/toJson
120108
final appConfigClient = HtDataApi<AppConfig>(
121109
httpClient: httpClient,
122-
modelName: 'app_config', // Assuming model name
110+
modelName: 'app_config',
123111
fromJson: AppConfig.fromJson,
124112
toJson: (config) => config.toJson(),
125113
);

pubspec.lock

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ packages:
8989
url: "https://pub.dev"
9090
source: hosted
9191
version: "1.4.0"
92+
checked_yaml:
93+
dependency: transitive
94+
description:
95+
name: checked_yaml
96+
sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff
97+
url: "https://pub.dev"
98+
source: hosted
99+
version: "2.0.3"
92100
cli_config:
93101
dependency: transitive
94102
description:
@@ -125,10 +133,10 @@ packages:
125133
dependency: transitive
126134
description:
127135
name: coverage
128-
sha256: "802bd084fb82e55df091ec8ad1553a7331b61c08251eef19a508b6f3f3a9858d"
136+
sha256: "4b8701e48a58f7712492c9b1f7ba0bb9d525644dd66d023b62e1fc8cdb560c8a"
129137
url: "https://pub.dev"
130138
source: hosted
131-
version: "1.13.1"
139+
version: "1.14.0"
132140
crypto:
133141
dependency: transitive
134142
description:
@@ -324,7 +332,7 @@ packages:
324332
description:
325333
path: "."
326334
ref: HEAD
327-
resolved-ref: "6cc5c3ccab072ad9f666a5a8d081216155423d32"
335+
resolved-ref: cc20fa6d3b396ade6c70c1e972fa75e9cf23e37c
328336
url: "https://github.com/headlines-toolkit/ht-auth-repository.git"
329337
source: git
330338
version: "0.0.0"
@@ -369,7 +377,7 @@ packages:
369377
description:
370378
path: "."
371379
ref: HEAD
372-
resolved-ref: "1c863118cf9f1ca785b8cb7943bcebbb987c9683"
380+
resolved-ref: c451604ef791eb70c7f7e2eda418afa463164c37
373381
url: "https://github.com/headlines-toolkit/ht-kv-storage-service.git"
374382
source: git
375383
version: "0.0.0"
@@ -671,6 +679,14 @@ packages:
671679
url: "https://pub.dev"
672680
source: hosted
673681
version: "2.2.0"
682+
pubspec_parse:
683+
dependency: transitive
684+
description:
685+
name: pubspec_parse
686+
sha256: "0560ba233314abbed0a48a2956f7f022cce7c3e1e73df540277da7544cad4082"
687+
url: "https://pub.dev"
688+
source: hosted
689+
version: "1.5.0"
674690
shared_preferences:
675691
dependency: transitive
676692
description:

0 commit comments

Comments
 (0)