removeUsername method
Implementation
Future<void> removeUsername({required String userId}) async {
_ensureConfigured();
final user = await _availableUser(
userId,
failureCode: 'username_removal_failed',
);
final credential = await _store.findUsernameForUser(user.id);
if (credential == null) return;
AuthAuthenticationMethodMutationResult result;
try {
result = await _store.removeUsernameIfSafe(
AuthUsernameRemovalCommand(
userId: user.id,
credentialId: credential.id,
loadInventory: () => _authenticationMethods.snapshotForUser(user.id),
),
);
} catch (_) {
throw AuthFlowException('username_removal_failed');
}
switch (result) {
case AuthAuthenticationMethodMutationResult.mutated:
case AuthAuthenticationMethodMutationResult.notFound:
return;
case AuthAuthenticationMethodMutationResult.lastAuthenticationMethod:
throw AuthFlowException('last_authentication_method');
case AuthAuthenticationMethodMutationResult.atomicityUnavailable:
throw AuthFlowException('authentication_method_mutation_unavailable');
}
}