forgot to push lol

This commit is contained in:
Kima 2024-11-14 17:12:38 +01:00
parent 414755c777
commit 521f609707
3 changed files with 27 additions and 5 deletions

View File

@ -29,7 +29,7 @@ import 'liveactivity/platform_channel.dart';
// Mutex
bool lock = false;
Future<void> syncAll(BuildContext context) {
Future<void> syncAll(BuildContext context) async {
if (lock) return Future.value();
// Lock
lock = true;
@ -62,7 +62,28 @@ Future<void> syncAll(BuildContext context) {
// print(user.user?.accessTokenExpire);
// print('${user.user?.accessToken ?? "no token"} - ACCESS TOKEN');
if (user.user == null) return;
// user.user!.accessToken = "";
if (user.user == null) {
Navigator.of(context).pushNamedAndRemoveUntil("login", (_) => false);
lock = false;
return Future.value();
}
if (user.user!.accessToken.replaceAll(" ", "") == "") {
String uid = user.user!.id;
user.removeUser(uid);
await Provider.of<DatabaseProvider>(context, listen: false)
.store
.removeUser(uid);
Navigator.of(context).pushNamedAndRemoveUntil("login", (_) => false);
lock = false;
return;
}
if (user.user!.accessTokenExpire.isBefore(DateTime.now())) {
String authRes = await Provider.of<KretaClient>(context, listen: false)
.refreshLogin() ??

View File

@ -237,7 +237,7 @@ class App extends StatelessWidget {
},
onGenerateRoute: (settings) => rootNavigator(settings),
initialRoute:
user.getUsers().isNotEmpty ? "navigation" : "login",
(user.getUsers().isNotEmpty) ? "navigation" : "login",
);
},
);

View File

@ -70,8 +70,9 @@ class User {
picture: map["picture"] ?? "",
gradeStreak: map["grade_streak"] ?? 0,
accessToken: map["access_token"] ?? "",
accessTokenExpire: DateTime.parse(
map["access_token_expire"] ?? DateTime.now().toIso8601String()),
accessTokenExpire: DateTime.parse(map["access_token_expire"] != ""
? map["access_token_expire"]
: DateTime.now().toIso8601String()),
refreshToken: map["refresh_token"] ?? "",
);
}