forked from eatvio/eatvio_app
Token is now saved to local storage properly
This commit is contained in:
@@ -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: () {
|
||||
|
||||
Reference in New Issue
Block a user