import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../../app/error_message.dart'; import '../../../app/load_state.dart'; import '../../../models/auth_info.dart'; import '../../shared/providers/core_providers.dart'; final authInfoProvider = NotifierProvider>( () => AuthInfoNotifier(), ); class AuthInfoNotifier extends Notifier> { @override LoadState build() => const LoadState.idle(null); Future load({bool failOnError = false}) async { state = LoadState.loading(state.data); try { final api = ref.read(apiProvider); final res = await api.getAuthMe(); final authInfo = AuthInfo.fromApi(res.data); state = LoadState.data(authInfo); return authInfo; } catch (e) { state = LoadState.error(null, describeLoadError(e)); if (failOnError) rethrow; return null; } } void clear() => state = const LoadState.idle(null); void restore(LoadState restoredState) => state = restoredState; bool get isAdmin => state.data?.isAdmin == true; }