import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:supabase_flutter/supabase_flutter.dart'; import '../../../../core/supabase/supabase_providers.dart'; import '../../data/services/auth_service.dart'; /// Provider for the AuthService. final authServiceProvider = Provider((ref) { final client = ref.watch(supabaseProvider); return AuthService(client); }); /// Provider for the current user's authentication state. final authStateProvider = StreamProvider((ref) { return ref.watch(authServiceProvider).onAuthStateChange; }); /// Controller for authentication actions. final authControllerProvider = AutoDisposeAsyncNotifierProvider( AuthController.new, ); class AuthController extends AutoDisposeAsyncNotifier { @override Future build() async {} Future login({required String email, required String password}) async { state = const AsyncLoading(); state = await AsyncValue.guard(() async { await ref.read(authServiceProvider).login( email: email.trim(), password: password, ); }); } Future signup({ required String email, required String password, required String username, }) async { state = const AsyncLoading(); state = await AsyncValue.guard(() async { await ref.read(authServiceProvider).signUp( email: email.trim(), password: password, username: username.trim(), ); }); } Future logout() async { state = const AsyncLoading(); state = await AsyncValue.guard(() async { await ref.read(authServiceProvider).logout(); }); } Future forgotPassword(String email) async { state = const AsyncLoading(); state = await AsyncValue.guard(() async { await ref.read(authServiceProvider).forgotPassword(email.trim()); }); } }