check token and auto redirect

This commit is contained in:
Valentin CZERYBA 2022-09-20 00:31:11 +02:00
parent 1fd6e56208
commit 53342d5520

View File

@ -124,15 +124,16 @@ class _LoginDemoState extends State<LoginDemo> 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");