addUserEmail method
- UserEmail email, {
- ConfirmationCode? confirmation,
- RawClientOptions? raw,
- String? locale,
Adds a new email address for the authenticated MyUser.
Sets the given email
address as an MyUserEmails.unconfirmed of a
MyUser.emails field and sends to this address an email message with a
ConfirmationCode.
Once User successfully uses this ConfirmationCode in a
Mutation.confirmUserEmail
, the email address becomes a confirmed one and
moves to MyUserEmails.confirmed sub-field unlocking the related
capabilities.
MyUser can have maximum one MyUserEmails.unconfirmed address at the same time.
Authentication
Mandatory.
Result
Only the following MyUserEvent may be produced on success:
Idempotent
Succeeds as no-op (and returns no MyUserEvent) if the provided email
is already present in a MyUser.emails field (either in confirmed or
unconfirmed sub-field).
Implementation
Future<MyUserEventsVersionedMixin?> addUserEmail(
UserEmail email, {
ConfirmationCode? confirmation,
RawClientOptions? raw,
String? locale,
}) async {
Log.debug(
'addUserEmail($email, confirmation: $confirmation, raw: $raw, locale: $locale)',
'$runtimeType',
);
final variables = AddUserEmailArguments(
email: email,
confirmation: confirmation,
);
final query = MutationOptions(
operationName: 'AddUserEmail',
document: AddUserEmailMutation(variables: variables).document,
variables: variables.toJson(),
);
final request = query.asRequest;
final body = const RequestSerializer().serializeRequest(request);
final encodedBody = json.encode(body);
final response = await client.post(
dio.FormData.fromMap({
'operations': encodedBody,
'map': '{ "token": ["variables.token"] }',
'token': raw?.token ?? token,
}),
options: dio.Options(
headers: {if (locale != null) 'Accept-Language': locale},
),
operationName: query.operationName,
onException:
(data) => AddUserEmailException(
(AddUserEmail$Mutation.fromJson(data).addUserEmail
as AddUserEmail$Mutation$AddUserEmail$AddUserEmailError)
.code,
),
);
if (response.data['data'] == null) {
throw GraphQlException([GraphQLError(message: response.data.toString())]);
}
return (AddUserEmail$Mutation.fromJson(response.data['data']).addUserEmail
as MyUserEventsVersionedMixin?);
}