forked from eatvio/eatvio_app
fix: auth
This commit is contained in:
@@ -17,11 +17,12 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
getTokenByCredentials(String email, String password) async {
|
getTokenByCredentials(String email, String password) async {
|
||||||
emit(AuthState.loading());
|
emit(AuthState.loading());
|
||||||
try {
|
try {
|
||||||
final String token = (await authRepository.getTokenByCredentials(
|
final token = (await authRepository.getTokenByCredentials(
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
))
|
))
|
||||||
.token;
|
.token;
|
||||||
|
print(token);
|
||||||
emit(
|
emit(
|
||||||
AuthState.loaded(
|
AuthState.loaded(
|
||||||
token: token,
|
token: token,
|
||||||
@@ -31,6 +32,7 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
await sl<ProfileAvatarCubit>().getMyProfile();
|
await sl<ProfileAvatarCubit>().getMyProfile();
|
||||||
AppRouter.navigatorKey.currentContext?.go('/my-profile-screen');
|
AppRouter.navigatorKey.currentContext?.go('/my-profile-screen');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
emit(AuthState.error(errorMessage: '$e'));
|
emit(AuthState.error(errorMessage: '$e'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,13 +24,14 @@ class _AuthScreenState extends State<AuthScreen> {
|
|||||||
final passwordController = TextEditingController();
|
final passwordController = TextEditingController();
|
||||||
bool checkboxState = false;
|
bool checkboxState = false;
|
||||||
bool hidePassword = true;
|
bool hidePassword = true;
|
||||||
|
final authCubit = sl<AuthCubit>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final s = S.of(context);
|
final s = S.of(context);
|
||||||
FlutterNativeSplash.remove();
|
FlutterNativeSplash.remove();
|
||||||
return BlocProvider<AuthCubit>(
|
return BlocProvider<AuthCubit>(
|
||||||
create: (BuildContext context) => sl<AuthCubit>(),
|
create: (BuildContext context) => authCubit,
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
@@ -131,7 +132,7 @@ class _AuthScreenState extends State<AuthScreen> {
|
|||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
),
|
),
|
||||||
backgroundColor: appTheme.blueA400,
|
backgroundColor: appTheme.blueA400,
|
||||||
onPressed: () => context.read<AuthCubit>().getTokenByCredentials(
|
onPressed: () => authCubit.getTokenByCredentials(
|
||||||
emailController.text,
|
emailController.text,
|
||||||
passwordController.text,
|
passwordController.text,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ part 'auth_service.g.dart';
|
|||||||
abstract class AuthService {
|
abstract class AuthService {
|
||||||
factory AuthService(Dio dio, {String? baseUrl}) = _AuthService;
|
factory AuthService(Dio dio, {String? baseUrl}) = _AuthService;
|
||||||
|
|
||||||
@GET('/api/login')
|
@POST('/api/login')
|
||||||
Future<TokenModel> getTokenByCredentials({
|
Future<TokenModel> getTokenByCredentials({
|
||||||
@Body() required CredentialsModel credentials,
|
@Body() required CredentialsModel credentials,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class _AuthService implements AuthService {
|
|||||||
final _headers = <String, dynamic>{};
|
final _headers = <String, dynamic>{};
|
||||||
final _data = credentials;
|
final _data = credentials;
|
||||||
final _options = _setStreamType<TokenModel>(
|
final _options = _setStreamType<TokenModel>(
|
||||||
Options(method: 'GET', headers: _headers, extra: _extra)
|
Options(method: 'POST', headers: _headers, extra: _extra)
|
||||||
.compose(
|
.compose(
|
||||||
_dio.options,
|
_dio.options,
|
||||||
'/api/login',
|
'/api/login',
|
||||||
|
|||||||
Reference in New Issue
Block a user