From 53342d552049b6e4fc46ad03da1bac9eeaa82096 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 20 Sep 2022 00:31:11 +0200 Subject: [PATCH] check token and auto redirect --- covas_mobile/lib/main.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/covas_mobile/lib/main.dart b/covas_mobile/lib/main.dart index b6345a4..c277981 100644 --- a/covas_mobile/lib/main.dart +++ b/covas_mobile/lib/main.dart @@ -124,15 +124,16 @@ class _LoginDemoState extends State with ShowErrorDialog { SharedPreferences prefs = await SharedPreferences.getInstance(); var jwt = prefs.getString("jwt") ?? ""; var user = prefs.getString("user") ?? ""; - stderr.writeln(jwt); if ((jwt.isNotEmpty) && (user.isNotEmpty)) { var urlToken = Uri.parse("http://localhost:8083/api/token"); var responseToken = await http.get(urlToken, headers: {HttpHeaders.cookieHeader: '${jwt}; ${user}'}); - stderr.writeln(responseToken.statusCode); if (responseToken.statusCode == 200) { - MaterialPageRoute(builder: (_) => MyHomePage(title: 'Flutter Demo')); + Navigator.push( + context, + MaterialPageRoute( + builder: (_) => MyHomePage(title: 'Flutter Demo'))); } else { prefs.remove("jwt"); prefs.remove("user");