From fea83bb7bded7815230f4f662f77ca8fb48e9702 Mon Sep 17 00:00:00 2001 From: BLoC Date: Mon, 17 Feb 2025 12:41:43 +0300 Subject: [PATCH] fix: auth --- lib/features/auth/presentation/bloc/auth_cubit.dart | 4 +++- lib/features/auth/presentation/pages/auth_screen.dart | 5 +++-- lib/features/auth/services/auth_service.dart | 2 +- lib/features/auth/services/auth_service.g.dart | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/features/auth/presentation/bloc/auth_cubit.dart b/lib/features/auth/presentation/bloc/auth_cubit.dart index 84917344..924247d1 100644 --- a/lib/features/auth/presentation/bloc/auth_cubit.dart +++ b/lib/features/auth/presentation/bloc/auth_cubit.dart @@ -17,11 +17,12 @@ class AuthCubit extends Cubit { getTokenByCredentials(String email, String password) async { emit(AuthState.loading()); try { - final String token = (await authRepository.getTokenByCredentials( + final token = (await authRepository.getTokenByCredentials( email, password, )) .token; + print(token); emit( AuthState.loaded( token: token, @@ -31,6 +32,7 @@ class AuthCubit extends Cubit { await sl().getMyProfile(); AppRouter.navigatorKey.currentContext?.go('/my-profile-screen'); } catch (e) { + print(e); emit(AuthState.error(errorMessage: '$e')); } } diff --git a/lib/features/auth/presentation/pages/auth_screen.dart b/lib/features/auth/presentation/pages/auth_screen.dart index 9a43569d..f620fb76 100644 --- a/lib/features/auth/presentation/pages/auth_screen.dart +++ b/lib/features/auth/presentation/pages/auth_screen.dart @@ -24,13 +24,14 @@ class _AuthScreenState extends State { final passwordController = TextEditingController(); bool checkboxState = false; bool hidePassword = true; + final authCubit = sl(); @override Widget build(BuildContext context) { final s = S.of(context); FlutterNativeSplash.remove(); return BlocProvider( - create: (BuildContext context) => sl(), + create: (BuildContext context) => authCubit, child: Scaffold( appBar: AppBar( centerTitle: true, @@ -131,7 +132,7 @@ class _AuthScreenState extends State { borderRadius: BorderRadius.circular(20), ), backgroundColor: appTheme.blueA400, - onPressed: () => context.read().getTokenByCredentials( + onPressed: () => authCubit.getTokenByCredentials( emailController.text, passwordController.text, ), diff --git a/lib/features/auth/services/auth_service.dart b/lib/features/auth/services/auth_service.dart index 89a2d49a..62256f8b 100644 --- a/lib/features/auth/services/auth_service.dart +++ b/lib/features/auth/services/auth_service.dart @@ -9,7 +9,7 @@ part 'auth_service.g.dart'; abstract class AuthService { factory AuthService(Dio dio, {String? baseUrl}) = _AuthService; - @GET('/api/login') + @POST('/api/login') Future getTokenByCredentials({ @Body() required CredentialsModel credentials, }); diff --git a/lib/features/auth/services/auth_service.g.dart b/lib/features/auth/services/auth_service.g.dart index d74516a4..2f3f6573 100644 --- a/lib/features/auth/services/auth_service.g.dart +++ b/lib/features/auth/services/auth_service.g.dart @@ -26,7 +26,7 @@ class _AuthService implements AuthService { final _headers = {}; final _data = credentials; final _options = _setStreamType( - Options(method: 'GET', headers: _headers, extra: _extra) + Options(method: 'POST', headers: _headers, extra: _extra) .compose( _dio.options, '/api/login',