Flutter + CloudCodeJS = No User Id in API requests

I am writing a Flutter app that should interact with my Backendless CloudCode. For some reason, when I make calls from Flutter to CloudCode, there is no userId in this.request.context. I have a user logged in and verified in the app. I have used this same code with JS client and I have used the built in request engine in Backendless and they both seem to work fine.

Here is my flutter code and its outputs:

void init() async {
    await Backendless.initApp(
        applicationId: APPLICATION_ID,
        androidApiKey: ANDROID_API_KEY,
        iosApiKey: IOS_API_KEY);

    List<String> channels = ["default"];
    Backendless.messaging.registerDevice(channels).then((response) {
      print("Device registered!");
    });

    var user = await Backendless.userService.getCurrentUser();
    if (user == null) {
      Navigator.push(context, MaterialPageRoute(builder: (_) => LoginPage()));
    } else {
      var userId = user.getUserId();
      print("User Id: $userId");
      var mood = await OctoMood.getMood(userId);
      print(mood);
    }
  }

Logs:

E/flutter (31735): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: BackendlessException: Access denied, code = 14008
E/flutter (31735): #0      Invoker.invoke.<anonymous closure>
package:backendless_sdk/…/common/invoker.dart:20
E/flutter (31735): #1      _rootRunUnary (dart:async/zone.dart:1362:47)
E/flutter (31735): #2      _CustomZone.runUnary (dart:async/zone.dart:1265:19)
E/flutter (31735): <asynchronous suspension>
E/flutter (31735): #3      _MyHomePageState.init
package:octomood/main.dart:55
E/flutter (31735): <asynchronous suspension>
E/flutter (31735):
I/flutter (31735): Device registered!
Restarted application in 776ms.
I/flutter (31735): Login page user: BackendlessUser{{lastLogin: 2021-10-24 13:29:27.840, userStatus: ENABLED, created: 2021-10-21 21:41:15.000, accountType: BACKENDLESS, ownerId: B454DEFE-553B-4C1A-818A-A488C6BCAEDD, socialAccount: BACKENDLESS, oAuthIdentities: null, name: null, ___class: Users, blUserLocale: en, updated: 2021-10-24 13:29:24.000, objectId: BFBD0788-F632-416E-ABDB-5DD874753C80, email: josh@greencrypted.com}}
I/flutter (31735): Build
I/flutter (31735): User Id: BFBD0788-F632-416E-ABDB-5DD874753C80

The Access Denied error is caused by access not being permitted to Unauthenticated users.

Here is my CloudCode:

async getMood( user ) {
    var response = "";
    var whereClause = "user like '" + user + "'";
    var queryBuilder = Backendless.DataQueryBuilder.create().setWhereClause( whereClause );
    
    var currentUserId = this.request.context.userId;
    console.log(this.request.context);
    
    if(currentUserId != null){
      if(currentUserId == user){
        await Backendless.Data.of( "moods" ).find( queryBuilder )
         .then( function( foundMoods ) {
           console.log(foundMoods[0].mood);
            var userMood = foundMoods[0];
            response = userMood.mood;
          })
         .catch( function( fault ) {
            response = fault;
          });
      } else {
        var followersArr = await this.getFollowers(user, true);
        
        if(followersArr.includes(currentUserId)){
         await Backendless.Data.of( "moods" ).find( queryBuilder )
           .then( function( foundMoods ) {
             console.log(foundMoods[0].mood);
              var userMood = foundMoods[0];
              response = userMood.mood;
            })
           .catch( function( fault ) {
              response = fault;
            });
         } else {
           response = "Unauthorized";
         }
        }
      } else {
        response = "Unauthorized";
      }
      console.log(response);
        return response;
    }

Hello, @joshua-green.

We are investigating your question.

Best Regards, Nikita.

We created a internal ticket BKNDLSS-26604.

When we have any news about this issue, we will let you know.

Best Regards, Nikita.

Could you try to call your API service using the Backendless console, does it work as it should?

Yes, it does. It is just Flutter API calls that are not working.

Thank you for your response.
We will let you know as soon as this issue is resolved.

Regards,
Alexander

We have released new version 7.1.6. Can you update plugin version and check if everything works fine for you now?

Best Regards, Nikita.

I updated my dependency to the new version, and it still isn’t showing a user. For some reason, I am also not getting any info in the Real-Time log or the log files.

Nevermind, I got the logging issue corrected and it looks like the user ID is now appearing in the request!

It looks like the argument I am passing to my API function is being shown as just a ‘[’ instead of the user-id string I am sending. This may be a separate problem. I have tried creating a test function to troubleshoot this issue. No matter what string i send to the API, ‘[’ is the only value that it outputs to the log.

Cloud Code

/**
   * @param {String} testStr
   */ 
  async test(testStr){
    console.log("Test String: ", testStr);
  }

Flutter Call:

OctoMood.test("test");

Log Output:

22:46:07 | SERVER_CODE | INFO | [24160] Test String: [

Hello, @joshua-green.

We have created an internal ticket BKNDLSS-26634.
When this is fixed, we’ll let you know in this thread.

Best Regards, Nikita.

Hello @joshua-green

We’ve just updated cloud servers with a fix for the issue you described above. Could you kindly let us know whether fix works for you well?

Regards,
Inna