Skip to content

Commit

Permalink
🐛 Stop login Process if it did not end with a login, too
Browse files Browse the repository at this point in the history
The login process is not ended correctly even if the method
does not end with the last return statement
  • Loading branch information
strifel committed Jul 27, 2020
1 parent ecc6c7c commit 72c8ac8
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,33 @@ class _User {
await Future.doWhile(() => _loggingIn);
return isLoggedIn();
}
// This variable has to be set at any return.
//TODO This does not seem like the perfect way to do this
_loggingIn = true;
SharedPreferences prefs = await SharedPreferences.getInstance();
// Check if the saved JWT is still valid if none is cached (This has to be done because a new jwt can not be issued before the old one is expired)
if (_jwt == null) {
_jwt = await prefs.getString("token");
if (isLoggedIn()) return true;
if (isLoggedIn()) {
_loggingIn = false;
return true;
}
}
// Load Refresh from disk if not cached
if (_refreshJWT == null) {
_refreshJWT = prefs.getString("refresh");
// We don't even need to try to login without refresh
if (_refreshJWT == null) return false;
if (_refreshJWT == null) {
_loggingIn = false;
return false;
}
}
var obj = await _APIConnection.refreshLogin(
prefs.getString("username"), _refreshJWT);
if (obj == null) return false;
if (obj == null) {
_loggingIn = false;
return false;
}
_jwt = obj["token"];
_refreshJWT = obj["refresh"];
prefs.setString("token", _jwt);
Expand Down

0 comments on commit 72c8ac8

Please sign in to comment.