changePassword method

  1. @override
Future<void> changePassword(
  1. String newPassword, {
  2. String? oldPassword,
  3. AuthenticationData? auth,
  4. bool? logoutDevices,
})

Changes the password. You should either set oldPasswort or another authentication flow.

Implementation

@override
Future<void> changePassword(String newPassword,
    {String? oldPassword,
    AuthenticationData? auth,
    bool? logoutDevices}) async {
  final userID = this.userID;
  try {
    if (oldPassword != null && userID != null) {
      auth = AuthenticationPassword(
        identifier: AuthenticationUserIdentifier(user: userID),
        password: oldPassword,
      );
    }
    await super.changePassword(newPassword,
        auth: auth, logoutDevices: logoutDevices);
  } on SDNException catch (sdnException) {
    if (!sdnException.requireAdditionalAuthentication) {
      rethrow;
    }
    if (sdnException.authenticationFlows?.length != 1 ||
        !(sdnException.authenticationFlows?.first.stages
                .contains(AuthenticationTypes.password) ??
            false)) {
      rethrow;
    }
    if (oldPassword == null || userID == null) {
      rethrow;
    }
    return changePassword(
      newPassword,
      auth: AuthenticationPassword(
        identifier: AuthenticationUserIdentifier(user: userID),
        password: oldPassword,
        session: sdnException.session,
      ),
      logoutDevices: logoutDevices,
    );
  } catch (_) {
    rethrow;
  }
}