import 'dart:developer'; import 'package:eatvio_app/core/token_storage.dart'; import 'package:eatvio_app/core/utils/toasts.dart'; import 'package:eatvio_app/features/auth/presentation/bloc/auth_state.dart'; import 'package:eatvio_app/features/auth/repositories/auth_repository.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; class AuthCubit extends Cubit { final AuthRepository authRepository; AuthCubit({ required this.authRepository, }) : super(const AuthState()); Future getTokenByCredentials(String email, String password) async { emit(const AuthState.loading()); try { final token = (await authRepository.getTokenByCredentials( email, password, )) .token; emit( AuthState.loaded( token: token, ), ); await TokenStorage.saveTokenInStorage(token); return true; } catch (e) { log(e.toString()); showErrorToast('Неверный адрес электронной почты или пароль'); emit(AuthState.error(errorMessage: '$e')); return false; } } }