diff --git a/lib/features/auth/data/datasource/auth_local_data_source.dart b/lib/features/auth/data/datasource/auth_local_data_source.dart index 7f1dbfc..9ffb0f1 100644 --- a/lib/features/auth/data/datasource/auth_local_data_source.dart +++ b/lib/features/auth/data/datasource/auth_local_data_source.dart @@ -7,7 +7,7 @@ import 'package:shared_preferences/src/shared_preferences_legacy.dart'; import '../../../../core/storage/shared_prefs_provider.dart'; final authLocalDataSourceProvider = Provider((ref) { - final prefs = ref.read(sharedPrefsProvider); + final prefs = ref.watch(sharedPrefsProvider); return AuthLocalDataSource(prefs); }); diff --git a/lib/features/auth/data/repositories/auth_repository_impl.dart b/lib/features/auth/data/repositories/auth_repository_impl.dart index 374fe1f..caeac1d 100644 --- a/lib/features/auth/data/repositories/auth_repository_impl.dart +++ b/lib/features/auth/data/repositories/auth_repository_impl.dart @@ -7,8 +7,8 @@ import '../datasource/auth_local_data_source.dart'; import '../models/user_model.dart'; final authRepositoryProvider = Provider((ref) { - final dio = ref.read(dioProvider); - final localDataSource = ref.read(authLocalDataSourceProvider); + final dio = ref.watch(dioProvider); + final localDataSource = ref.watch(authLocalDataSourceProvider); return AuthRepositoryImpl(dio, localDataSource); }); diff --git a/lib/features/auth/presentation/providers/auth_controller.dart b/lib/features/auth/presentation/providers/auth_controller.dart index 6848f37..f9e66fb 100644 --- a/lib/features/auth/presentation/providers/auth_controller.dart +++ b/lib/features/auth/presentation/providers/auth_controller.dart @@ -16,12 +16,13 @@ class AuthController extends AsyncNotifier { @override Future build() async { - final authLocalDataSource = ref.read(authLocalDataSourceProvider); + final authLocalDataSource = ref.watch(authLocalDataSourceProvider); final user = authLocalDataSource.getUser(); if (user != null) { - final bool = _checkTokenValidity(user); - return await bool ? user : null; + final repository = ref.watch(authRepositoryProvider); + final isValid = await repository.isTokenValid(user.token); + return isValid ? user : null; } return null; @@ -37,12 +38,6 @@ class AuthController extends AsyncNotifier { return repository.login(username, password); }); } - - Future _checkTokenValidity(User user) async { - final repository = ref.read(authRepositoryProvider); - return repository.isTokenValid(user.token); - - } void logout() { state = const AsyncValue.data(null);