A
This commit is contained in:
@@ -17,6 +17,7 @@ class TwoFactorProvider extends ChangeNotifier {
|
||||
bool _hasError = false;
|
||||
bool _verificationSuccess = false;
|
||||
String? _errorMessage;
|
||||
String? _currentPendingToken;
|
||||
|
||||
bool get isSubmitting => _isSubmitting;
|
||||
bool get hasError => _hasError;
|
||||
@@ -26,6 +27,12 @@ class TwoFactorProvider extends ChangeNotifier {
|
||||
|
||||
void update(AccountProvider accountProvider) {
|
||||
_accountProvider = accountProvider;
|
||||
final pending = accountProvider.pendingLogin;
|
||||
final token = pending?.pendingToken.token;
|
||||
if (token != _currentPendingToken || accountProvider.account == null) {
|
||||
_resetState();
|
||||
_currentPendingToken = token;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> submitCode(String code) async {
|
||||
@@ -46,6 +53,7 @@ class TwoFactorProvider extends ChangeNotifier {
|
||||
);
|
||||
_accountProvider.completePendingLogin(account);
|
||||
_verificationSuccess = true;
|
||||
_currentPendingToken = null;
|
||||
} catch (e) {
|
||||
_hasError = true;
|
||||
_errorMessage = e.toString();
|
||||
@@ -71,4 +79,17 @@ class TwoFactorProvider extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void reset() {
|
||||
_resetState();
|
||||
_currentPendingToken = null;
|
||||
}
|
||||
|
||||
void _resetState() {
|
||||
_isSubmitting = false;
|
||||
_hasError = false;
|
||||
_errorMessage = null;
|
||||
_verificationSuccess = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user