deleteUserEmail method
- UserEmail email, {
- UserPassword? password,
- ConfirmationCode? confirmation,
override
Deletes the given email
from MyUser.emails of the authenticated
MyUser.
Implementation
@override
Future<void> deleteUserEmail(
UserEmail email, {
UserPassword? password,
ConfirmationCode? confirmation,
}) async {
Log.debug(
'deleteUserEmail($email, password: ${password?.obscured}, confirmation: $confirmation)',
'$runtimeType',
);
if (myUser.value?.emails.unconfirmed == email) {
await _debounce(
field: MyUserField.email,
current: () => myUser.value?.emails.unconfirmed,
saved: () async => (await _active)?.value.emails.unconfirmed,
value: null,
mutation: (value, previous) async {
if (previous != null) {
return await _graphQlProvider.deleteUserEmail(
previous,
confirmation:
confirmation == null && password == null
? null
: MyUserCredentials(
code: confirmation,
password: password,
),
);
} else if (value != null) {
return await _graphQlProvider.addUserEmail(
value,
confirmation: confirmation,
);
}
return null;
},
update:
(v, p) => myUser.update(
(u) =>
p != null
? u?.emails.unconfirmed = null
: u?.emails.unconfirmed = v,
),
);
} else {
int i = myUser.value?.emails.confirmed.indexOf(email) ?? -1;
if (i != -1) {
myUser.update((u) => u?.emails.confirmed.remove(email));
}
try {
await _graphQlProvider.deleteUserEmail(
email,
confirmation:
confirmation == null && password == null
? null
: MyUserCredentials(code: confirmation, password: password),
);
} catch (_) {
if (i != -1) {
i = min(i, myUser.value?.emails.confirmed.length ?? 0);
myUser.update((u) => myUser.value?.emails.confirmed.insert(i, email));
}
rethrow;
}
}
}