changeEmail method
Changes the email of the user to a new one.
If email confirmation is disabled in your app authentication settings, it immediately updates the user's email and returns back the updated user data.
If email confirmation is enabled in your app authentication settings, it sends a confirmation email to the new email address with a link for the user to click and returns the current user's info. Until the user clicks on the link, the user's email address will not be changed to the new one.
An active user session is required (e.g., user needs to be logged in) to call this method.
currentPassword
The password of the user
newEmail
The new email address of the user
Implementation
Future<UserResult> changeEmail(
String currentPassword, String newEmail) async {
var res = await _fetcher.post<Map<String, dynamic>>(
'/_api/rest/v1/auth/change-email',
body: {'currentPassword': currentPassword, 'newEmail': newEmail});
return UserResult(
errors: res.errors,
user: res.errors == null
? (res.data?['user'] as Map<String, dynamic>?) == null
? null
: User.fromJson(res.data?['user'] as Map<String, dynamic>)
: null);
}