checkpoint
This commit is contained in:
@@ -13,7 +13,11 @@ final authServiceProvider = Provider<AuthService>((ref) {
|
||||
});
|
||||
|
||||
final apiClientProvider = Provider<CqrsApiClient>((ref) {
|
||||
return CqrsApiClient(config: ApiClientConfig.development);
|
||||
final authService = ref.watch(authServiceProvider);
|
||||
return CqrsApiClient(
|
||||
config: ApiClientConfig.development,
|
||||
authService: authService,
|
||||
);
|
||||
});
|
||||
|
||||
final isAuthenticatedProvider = FutureProvider<bool>((ref) async {
|
||||
@@ -34,19 +38,17 @@ final authTokenProvider = FutureProvider<String?>((ref) async {
|
||||
});
|
||||
|
||||
final deliveryRoutesProvider = FutureProvider<List<DeliveryRoute>>((ref) async {
|
||||
final token = await ref.read(authTokenProvider.future);
|
||||
final authService = ref.watch(authServiceProvider);
|
||||
final isAuthenticated = await authService.isAuthenticated();
|
||||
|
||||
if (token == null) {
|
||||
if (!isAuthenticated) {
|
||||
throw Exception('User not authenticated');
|
||||
}
|
||||
|
||||
// Create a new client with auth token
|
||||
// Create a new client with auth service for automatic token refresh
|
||||
final authClient = CqrsApiClient(
|
||||
config: ApiClientConfig(
|
||||
baseUrl: ApiClientConfig.development.baseUrl,
|
||||
defaultHeaders: {'Authorization': 'Bearer $token'},
|
||||
allowSelfSignedCertificate: ApiClientConfig.development.allowSelfSignedCertificate,
|
||||
),
|
||||
config: ApiClientConfig.development,
|
||||
authService: authService,
|
||||
);
|
||||
|
||||
final result = await authClient.executeQuery<List<DeliveryRoute>>(
|
||||
@@ -68,18 +70,16 @@ final deliveryRoutesProvider = FutureProvider<List<DeliveryRoute>>((ref) async {
|
||||
});
|
||||
|
||||
final deliveriesProvider = FutureProvider.family<List<Delivery>, int>((ref, routeFragmentId) async {
|
||||
final token = await ref.read(authTokenProvider.future);
|
||||
final authService = ref.watch(authServiceProvider);
|
||||
final isAuthenticated = await authService.isAuthenticated();
|
||||
|
||||
if (token == null) {
|
||||
if (!isAuthenticated) {
|
||||
throw Exception('User not authenticated');
|
||||
}
|
||||
|
||||
final authClient = CqrsApiClient(
|
||||
config: ApiClientConfig(
|
||||
baseUrl: ApiClientConfig.development.baseUrl,
|
||||
defaultHeaders: {'Authorization': 'Bearer $token'},
|
||||
allowSelfSignedCertificate: ApiClientConfig.development.allowSelfSignedCertificate,
|
||||
),
|
||||
config: ApiClientConfig.development,
|
||||
authService: authService,
|
||||
);
|
||||
|
||||
final result = await authClient.executeQuery<List<Delivery>>(
|
||||
@@ -128,7 +128,7 @@ final allDeliveriesProvider = FutureProvider<List<Delivery>>((ref) async {
|
||||
// Language notifier for state management
|
||||
class LanguageNotifier extends Notifier<String> {
|
||||
@override
|
||||
String build() => 'fr';
|
||||
String build() => 'system';
|
||||
|
||||
void setLanguage(String lang) => state = lang;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user