changePassword method

Future<AuthResponse<void>> changePassword({
  1. required String newPassword,
  2. String? oldPassword,
})

Changes the user's password.

newPassword The new password (required). oldPassword The current password (optional, depends on server config).

Returns an AuthResponse indicating success or failure.

Example:

final response = await authClient.account.changePassword(
  newPassword: 'newPassword123',
  oldPassword: 'oldPassword123',
);

if (response.isSuccess) {
  print('Password changed successfully');
}

Implementation

Future<AuthResponse<void>> changePassword({
  required String newPassword,
  String? oldPassword,
}) async {
  try {
    await _dio.post(
      ApiEndpoints.changePassword,
      data: {
        'newPassword': newPassword,
        if (oldPassword != null) 'oldPassword': oldPassword,
      },
    );
    return AuthResponse.success(null);
  } on DioException catch (e) {
    return AuthResponse.error(AuthError.fromDio(e));
  }
}