✨ Better to solve multi-factor authenticate
This commit is contained in:
@ -26,7 +26,7 @@ class AuthProvider extends ChangeNotifier {
|
||||
|
||||
DateTime? lastRefreshedAt;
|
||||
|
||||
Future<bool> pickClient() async {
|
||||
Future<bool> loadClient() async {
|
||||
if (await storage.containsKey(key: storageKey)) {
|
||||
try {
|
||||
final credentials = oauth2.Credentials.fromJson((await storage.read(key: storageKey))!);
|
||||
@ -43,7 +43,7 @@ class AuthProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<oauth2.Client> createClient(BuildContext context, String username, String password) async {
|
||||
if (await pickClient()) {
|
||||
if (await loadClient()) {
|
||||
return client!;
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ class AuthProvider extends ChangeNotifier {
|
||||
const storage = FlutterSecureStorage();
|
||||
if (await storage.containsKey(key: storageKey)) {
|
||||
if (client == null) {
|
||||
await pickClient();
|
||||
await loadClient();
|
||||
}
|
||||
if (lastRefreshedAt == null || DateTime.now().subtract(const Duration(minutes: 3)).isAfter(lastRefreshedAt!)) {
|
||||
await refreshToken();
|
||||
|
@ -22,7 +22,7 @@ class ChatProvider extends ChangeNotifier {
|
||||
ChatCallInstance? call;
|
||||
|
||||
Future<WebSocketChannel?> connect(AuthProvider auth) async {
|
||||
if (auth.client == null) await auth.pickClient();
|
||||
if (auth.client == null) await auth.loadClient();
|
||||
if (!await auth.isAuthorized()) return null;
|
||||
|
||||
await auth.refreshToken();
|
||||
|
@ -61,7 +61,7 @@ class NotifyProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<WebSocketChannel?> connect(AuthProvider auth) async {
|
||||
if (auth.client == null) await auth.pickClient();
|
||||
if (auth.client == null) await auth.loadClient();
|
||||
if (!await auth.isAuthorized()) return null;
|
||||
|
||||
await auth.refreshToken();
|
||||
|
Reference in New Issue
Block a user