Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:shared_preferences/src/shared_preferences_legacy.dart';
import '../../../../core/storage/shared_prefs_provider.dart';

final authLocalDataSourceProvider = Provider<AuthLocalDataSource>((ref) {
final prefs = ref.read(sharedPrefsProvider);
final prefs = ref.watch(sharedPrefsProvider);
return AuthLocalDataSource(prefs);
});

Expand Down
4 changes: 2 additions & 2 deletions lib/features/auth/data/repositories/auth_repository_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import '../datasource/auth_local_data_source.dart';
import '../models/user_model.dart';

final authRepositoryProvider = Provider<AuthRepository>((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);
});

Expand Down
13 changes: 4 additions & 9 deletions lib/features/auth/presentation/providers/auth_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ class AuthController extends AsyncNotifier<User?> {

@override
Future<User?> 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;
Expand All @@ -37,12 +38,6 @@ class AuthController extends AsyncNotifier<User?> {
return repository.login(username, password);
});
}

Future<bool> _checkTokenValidity(User user) async {
final repository = ref.read(authRepositoryProvider);
return repository.isTokenValid(user.token);

}

void logout() {
state = const AsyncValue.data(null);
Expand Down