From cf84bf8e2f753633627623194598506d3ad833fa Mon Sep 17 00:00:00 2001 From: maxxkim Date: Thu, 11 Jan 2024 11:45:19 +0300 Subject: [PATCH] Token is now saved to local storage properly --- .../auth/auth_screen/auth_screen.dart | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/presentation/auth/auth_screen/auth_screen.dart b/lib/presentation/auth/auth_screen/auth_screen.dart index d1159b4a..143ab549 100644 --- a/lib/presentation/auth/auth_screen/auth_screen.dart +++ b/lib/presentation/auth/auth_screen/auth_screen.dart @@ -83,17 +83,16 @@ class AuthScreen extends StatelessWidget { 'password': state.passwordController!.text, }; final response = await http.post( - Uri.parse('http://10.55.5.126:1092/api/login'), - headers: {'Content-Type': 'application/json'}, - body: json.encode(credentials), - ); + Uri.parse('http://10.55.5.126:1092/api/login'), + headers: {'Content-Type': 'application/json'}, + body: json.encode(credentials), + encoding: utf8); if (response.statusCode == 200) { - print(response.body); + var res = await jsonDecode(response.body); final box = await Hive.openBox('token'); - final token = json.decode(response.body)['token'] - ['plainTextToken']; + final token = res['token']['plainTextToken']; box.put('token', token); - print('token: ${box.get('token')}'); + print(token); Navigator.pushNamed( context, AppRoutes.myProfile, @@ -104,7 +103,7 @@ class AuthScreen extends StatelessWidget { builder: (context) => AlertDialog( title: Text('Ошибка'), content: - Text(jsonDecode(response.body)['message']), + Text(jsonDecode(jsonEncode(response.body))), actions: [ TextButton( onPressed: () {