changePhone method

Future<UserResult> changePhone(
  1. String currentPassword,
  2. String newPhone
)

Changes the phone number of the user to a new one.

If phone number confirmation is disabled in your app authentication settings, it immediately updates the user's phone number and returns back the updated user data.

If phone number confirmation is enabled in your app authentication settings, it sends a confirmation SMS code to the new phone number and returns the current user's info. After sending the SMS code by calling this method, you need to show a form to the user to enter this SMS code and call verifyPhone method with the new phone number and the code to change user's phone number 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

newPhone The new phone number of the user

Implementation

Future<UserResult> changePhone(
    String currentPassword, String newPhone) async {
  var res = await _fetcher.post<Map<String, dynamic>>(
      '/_api/rest/v1/auth/change-phone',
      body: {'currentPassword': currentPassword, 'newPhone': newPhone});

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