Better to solve multi-factor authenticate

This commit is contained in:
2024-05-01 11:27:48 +08:00
parent 5d79692766
commit 28c0094837
5 changed files with 38 additions and 19 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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();