unified code verification service
This commit is contained in:
@@ -7,7 +7,7 @@ import 'package:share_plus/share_plus.dart';
|
||||
import 'package:pshared/api/errors/unauthorized.dart';
|
||||
import 'package:pshared/api/requests/signup.dart';
|
||||
import 'package:pshared/api/requests/login_data.dart';
|
||||
import 'package:pshared/api/responses/confirmation.dart';
|
||||
import 'package:pshared/api/responses/verification/response.dart';
|
||||
import 'package:pshared/config/constants.dart';
|
||||
import 'package:pshared/models/account/account.dart';
|
||||
import 'package:pshared/models/auth/login_outcome.dart';
|
||||
@@ -93,16 +93,16 @@ class AccountProvider extends ChangeNotifier {
|
||||
password: password,
|
||||
locale: locale,
|
||||
));
|
||||
if (outcome.account != null) {
|
||||
if (outcome.isCompleted) {
|
||||
_authState = AuthState.ready;
|
||||
_setResource(Resource(data: outcome.account, isLoading: false));
|
||||
_pickupLocale(outcome.account!.locale);
|
||||
} else {
|
||||
final pending = outcome.pending;
|
||||
if (pending == null) {
|
||||
throw Exception('Pending login data is missing');
|
||||
if (!outcome.isPending || pending == null) {
|
||||
throw StateError('Pending login data is missing');
|
||||
}
|
||||
final confirmation = await VerificationService.requestLoginCode(pending);
|
||||
final confirmation = await VerificationService.requestLoginCode(pending, target: email);
|
||||
_pendingLogin = _applyConfirmationMeta(pending, confirmation);
|
||||
_authState = AuthState.idle;
|
||||
_setResource(_resource.copyWith(isLoading: false));
|
||||
@@ -115,7 +115,10 @@ class AccountProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
PendingLogin _applyConfirmationMeta(PendingLogin pending, ConfirmationResponse confirmation) {
|
||||
PendingLogin _applyConfirmationMeta(
|
||||
PendingLogin pending,
|
||||
VerificationResponse confirmation,
|
||||
) {
|
||||
final ttlSeconds = confirmation.ttlSeconds != 0 ? confirmation.ttlSeconds : pending.ttlSeconds;
|
||||
final destination = confirmation.destination.isNotEmpty ? confirmation.destination : pending.destination;
|
||||
final cooldownSeconds = confirmation.cooldownSeconds;
|
||||
@@ -126,10 +129,11 @@ class AccountProvider extends ChangeNotifier {
|
||||
cooldownSeconds: cooldownSeconds > 0 ? cooldownSeconds : null,
|
||||
cooldownUntil: cooldownSeconds > 0 ? DateTime.now().add(confirmation.cooldownDuration) : null,
|
||||
clearCooldown: cooldownSeconds <= 0,
|
||||
idempotencyKey: confirmation.idempotencyKey,
|
||||
);
|
||||
}
|
||||
|
||||
void updatePendingLogin(ConfirmationResponse confirmation) {
|
||||
void updatePendingLogin(VerificationResponse confirmation) {
|
||||
final pending = _pendingLogin;
|
||||
if (pending == null) return;
|
||||
_pendingLogin = _applyConfirmationMeta(pending, confirmation);
|
||||
|
||||
Reference in New Issue
Block a user