forked from firka/student-legacy
fixed login finally
This commit is contained in:
parent
2dafe5ed02
commit
38d9b5f3b2
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:refilc/api/providers/database_provider.dart';
|
import 'package:refilc/api/providers/database_provider.dart';
|
||||||
import 'package:refilc/api/providers/status_provider.dart';
|
import 'package:refilc/api/providers/status_provider.dart';
|
||||||
import 'package:refilc/api/providers/user_provider.dart';
|
import 'package:refilc/api/providers/user_provider.dart';
|
||||||
@ -58,7 +59,8 @@ Future<void> syncAll(BuildContext context) {
|
|||||||
tasks = [
|
tasks = [
|
||||||
// refresh login
|
// refresh login
|
||||||
syncStatus(() async {
|
syncStatus(() async {
|
||||||
print(user.user?.accessTokenExpire);
|
// print(user.user?.accessTokenExpire);
|
||||||
|
// print('${user.user?.accessToken ?? "no token"} - ACCESS TOKEN');
|
||||||
|
|
||||||
if (user.user == null) return;
|
if (user.user == null) return;
|
||||||
if (user.user!.accessTokenExpire.isBefore(DateTime.now())) {
|
if (user.user!.accessTokenExpire.isBefore(DateTime.now())) {
|
||||||
@ -66,12 +68,14 @@ Future<void> syncAll(BuildContext context) {
|
|||||||
.refreshLogin() ??
|
.refreshLogin() ??
|
||||||
'';
|
'';
|
||||||
if (authRes != 'success') {
|
if (authRes != 'success') {
|
||||||
print('ERROR: failed to refresh login');
|
if (kDebugMode) print('ERROR: failed to refresh login');
|
||||||
lock = false;
|
lock = false;
|
||||||
return Future.value();
|
return Future.value();
|
||||||
|
} else {
|
||||||
|
if (kDebugMode) print('INFO: access token refreshed');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print('INFO: access token is not expired');
|
if (kDebugMode) print('INFO: access token is not expired');
|
||||||
}
|
}
|
||||||
}()),
|
}()),
|
||||||
|
|
||||||
|
@ -304,7 +304,7 @@ class KretaClient {
|
|||||||
|
|
||||||
if (res.containsKey("access_token")) {
|
if (res.containsKey("access_token")) {
|
||||||
accessToken = res["access_token"];
|
accessToken = res["access_token"];
|
||||||
loginUser.accessToken = res["refresh_token"];
|
loginUser.accessToken = res["access_token"];
|
||||||
loginUser.accessTokenExpire =
|
loginUser.accessTokenExpire =
|
||||||
DateTime.now().add(Duration(seconds: (res["expires_in"] - 30)));
|
DateTime.now().add(Duration(seconds: (res["expires_in"] - 30)));
|
||||||
_database.store.storeUser(loginUser);
|
_database.store.storeUser(loginUser);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user