fix
This commit is contained in:
@@ -1,14 +1,44 @@
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import '../../../../core/di/injection_container.dart';
|
||||
import '../../../../core/network/dio_client.dart';
|
||||
import '../../../../core/storage/secure_storage.dart';
|
||||
import '../../data/datasources/auth_remote_datasource.dart';
|
||||
import '../../data/repositories/auth_repository_impl.dart';
|
||||
import '../../domain/entities/user.dart';
|
||||
import '../../domain/repositories/auth_repository.dart';
|
||||
|
||||
part 'auth_provider.g.dart';
|
||||
|
||||
/// Provider for DioClient (singleton)
|
||||
@Riverpod(keepAlive: true)
|
||||
DioClient dioClient(Ref ref) {
|
||||
return DioClient();
|
||||
}
|
||||
|
||||
/// Provider for SecureStorage (singleton)
|
||||
@Riverpod(keepAlive: true)
|
||||
SecureStorage secureStorage(Ref ref) {
|
||||
return SecureStorage();
|
||||
}
|
||||
|
||||
/// Provider for AuthRemoteDataSource
|
||||
@Riverpod(keepAlive: true)
|
||||
AuthRemoteDataSource authRemoteDataSource(Ref ref) {
|
||||
final dioClient = ref.watch(dioClientProvider);
|
||||
return AuthRemoteDataSourceImpl(dioClient: dioClient);
|
||||
}
|
||||
|
||||
/// Provider for AuthRepository
|
||||
@riverpod
|
||||
@Riverpod(keepAlive: true)
|
||||
AuthRepository authRepository(Ref ref) {
|
||||
return sl<AuthRepository>();
|
||||
final remoteDataSource = ref.watch(authRemoteDataSourceProvider);
|
||||
final secureStorage = ref.watch(secureStorageProvider);
|
||||
final dioClient = ref.watch(dioClientProvider);
|
||||
|
||||
return AuthRepositoryImpl(
|
||||
remoteDataSource: remoteDataSource,
|
||||
secureStorage: secureStorage,
|
||||
dioClient: dioClient,
|
||||
);
|
||||
}
|
||||
|
||||
/// Auth state class
|
||||
@@ -45,14 +75,15 @@ class AuthState {
|
||||
class Auth extends _$Auth {
|
||||
@override
|
||||
AuthState build() {
|
||||
_checkAuthStatus();
|
||||
// Don't call async operations in build
|
||||
// Use a separate method to initialize auth state
|
||||
return const AuthState();
|
||||
}
|
||||
|
||||
AuthRepository get _repository => ref.read(authRepositoryProvider);
|
||||
|
||||
/// Check if user is authenticated on app start
|
||||
Future<void> _checkAuthStatus() async {
|
||||
/// Initialize auth state - call this on app start
|
||||
Future<void> initialize() async {
|
||||
state = state.copyWith(isLoading: true);
|
||||
|
||||
final isAuthenticated = await _repository.isAuthenticated();
|
||||
|
||||
@@ -8,6 +8,151 @@ part of 'auth_provider.dart';
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
/// Provider for DioClient (singleton)
|
||||
|
||||
@ProviderFor(dioClient)
|
||||
const dioClientProvider = DioClientProvider._();
|
||||
|
||||
/// Provider for DioClient (singleton)
|
||||
|
||||
final class DioClientProvider
|
||||
extends $FunctionalProvider<DioClient, DioClient, DioClient>
|
||||
with $Provider<DioClient> {
|
||||
/// Provider for DioClient (singleton)
|
||||
const DioClientProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'dioClientProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$dioClientHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<DioClient> $createElement($ProviderPointer pointer) =>
|
||||
$ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
DioClient create(Ref ref) {
|
||||
return dioClient(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(DioClient value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<DioClient>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$dioClientHash() => r'895f0dc2f8d5eab562ad65390e5c6d4a1f722b0d';
|
||||
|
||||
/// Provider for SecureStorage (singleton)
|
||||
|
||||
@ProviderFor(secureStorage)
|
||||
const secureStorageProvider = SecureStorageProvider._();
|
||||
|
||||
/// Provider for SecureStorage (singleton)
|
||||
|
||||
final class SecureStorageProvider
|
||||
extends $FunctionalProvider<SecureStorage, SecureStorage, SecureStorage>
|
||||
with $Provider<SecureStorage> {
|
||||
/// Provider for SecureStorage (singleton)
|
||||
const SecureStorageProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'secureStorageProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$secureStorageHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<SecureStorage> $createElement($ProviderPointer pointer) =>
|
||||
$ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
SecureStorage create(Ref ref) {
|
||||
return secureStorage(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(SecureStorage value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<SecureStorage>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$secureStorageHash() => r'5c9908c0046ad0e39469ee7acbb5540397b36693';
|
||||
|
||||
/// Provider for AuthRemoteDataSource
|
||||
|
||||
@ProviderFor(authRemoteDataSource)
|
||||
const authRemoteDataSourceProvider = AuthRemoteDataSourceProvider._();
|
||||
|
||||
/// Provider for AuthRemoteDataSource
|
||||
|
||||
final class AuthRemoteDataSourceProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
AuthRemoteDataSource,
|
||||
AuthRemoteDataSource,
|
||||
AuthRemoteDataSource
|
||||
>
|
||||
with $Provider<AuthRemoteDataSource> {
|
||||
/// Provider for AuthRemoteDataSource
|
||||
const AuthRemoteDataSourceProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'authRemoteDataSourceProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$authRemoteDataSourceHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<AuthRemoteDataSource> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
AuthRemoteDataSource create(Ref ref) {
|
||||
return authRemoteDataSource(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(AuthRemoteDataSource value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<AuthRemoteDataSource>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$authRemoteDataSourceHash() =>
|
||||
r'83759467bf61c03cf433b26d1126b19ab1d2b493';
|
||||
|
||||
/// Provider for AuthRepository
|
||||
|
||||
@ProviderFor(authRepository)
|
||||
@@ -25,7 +170,7 @@ final class AuthRepositoryProvider
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'authRepositoryProvider',
|
||||
isAutoDispose: true,
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
@@ -52,7 +197,7 @@ final class AuthRepositoryProvider
|
||||
}
|
||||
}
|
||||
|
||||
String _$authRepositoryHash() => r'0483b13ac95333b56a1a82f6c9fdb64ae46f287d';
|
||||
String _$authRepositoryHash() => r'5a333f81441082dd473e9089124aa65fda42be7b';
|
||||
|
||||
/// Auth state notifier provider
|
||||
|
||||
@@ -89,7 +234,7 @@ final class AuthProvider extends $NotifierProvider<Auth, AuthState> {
|
||||
}
|
||||
}
|
||||
|
||||
String _$authHash() => r'c88e150224fa855ed0ddfba30bef9e2b289f329d';
|
||||
String _$authHash() => r'67ba3b381308cce5e693827ad22db940840c3978';
|
||||
|
||||
/// Auth state notifier provider
|
||||
|
||||
|
||||
Reference in New Issue
Block a user