import 'package:eatvio_app/core/app_router.dart'; import 'package:eatvio_app/core/locator_service.dart'; import 'package:eatvio_app/core/token_storage.dart'; import 'package:eatvio_app/features/auth/presentation/bloc/auth_state.dart'; import 'package:eatvio_app/features/auth/repositories/auth_repository.dart'; import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/profile_avatar_cubit/profile_avatar_cubit.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; class AuthCubit extends Cubit { final AuthRepository authRepository; AuthCubit({ required this.authRepository, }) : super(AuthState()); getTokenByCredentials(String email, String password) async { emit(AuthState.loading()); try { final token = (await authRepository.getTokenByCredentials( email, password, )) .token; print(token); emit( AuthState.loaded( token: token, ), ); await TokenStorage.saveTokenInStorage(token); await sl().getMyProfile(); AppRouter.navigatorKey.currentContext?.go('/my-profile-screen'); } catch (e) { print(e); emit(AuthState.error(errorMessage: '$e')); } } }