sneaky email verification fix

This commit is contained in:
Arseni
2026-02-05 02:54:13 +03:00
parent 0ce90eef21
commit 81ffdd4291
6 changed files with 266 additions and 81 deletions

View File

@@ -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)),
);
}
}