sneaky email verification fix
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/api/responses/error/server.dart';
|
||||
import 'package:pshared/provider/resource.dart';
|
||||
import 'package:pshared/service/account.dart';
|
||||
import 'package:pshared/utils/exception.dart';
|
||||
|
||||
|
||||
class EmailVerificationProvider extends ChangeNotifier {
|
||||
Resource<bool> _resource = Resource(data: null, isLoading: false);
|
||||
String? _token;
|
||||
@@ -13,6 +13,11 @@ class EmailVerificationProvider extends ChangeNotifier {
|
||||
bool get isLoading => _resource.isLoading;
|
||||
bool get isSuccess => _resource.data == true;
|
||||
Exception? get error => _resource.error;
|
||||
int? get errorCode => _resource.error is ErrorResponse
|
||||
? (_resource.error as ErrorResponse).code
|
||||
: null;
|
||||
bool get canResendVerification =>
|
||||
errorCode == 400 || errorCode == 410 || errorCode == 500;
|
||||
|
||||
Future<void> verify(String token) async {
|
||||
final trimmed = token.trim();
|
||||
@@ -33,12 +38,12 @@ class EmailVerificationProvider extends ChangeNotifier {
|
||||
await AccountService.verifyEmail(trimmed);
|
||||
_setResource(Resource(data: true, isLoading: false));
|
||||
} catch (e) {
|
||||
if (e is ErrorResponse && e.code == 404) {
|
||||
_setResource(Resource(data: true, isLoading: false));
|
||||
return;
|
||||
}
|
||||
_setResource(
|
||||
Resource(
|
||||
data: null,
|
||||
isLoading: false,
|
||||
error: toException(e),
|
||||
),
|
||||
Resource(data: null, isLoading: false, error: toException(e)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user