From 1fd6e56208d3b0974caada95e1acf0cd93ce5200 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 18 Sep 2022 22:44:15 +0200 Subject: [PATCH] start functions with response token wip --- covas_mobile/lib/main.dart | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/covas_mobile/lib/main.dart b/covas_mobile/lib/main.dart index 7bb6088..b6345a4 100644 --- a/covas_mobile/lib/main.dart +++ b/covas_mobile/lib/main.dart @@ -122,7 +122,22 @@ class _LoginDemoState extends State with ShowErrorDialog { void start() async { SharedPreferences prefs = await SharedPreferences.getInstance(); - stderr.writeln(prefs.getString("jwt")); + 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')); + } else { + prefs.remove("jwt"); + prefs.remove("user"); + } + } } @override