How to call cloud function in anther cloud functions?

I have a cloud function:

Parse.Cloud.define("funA", async function (request) {
    var user  = request.user;
    if(!user){
   throw new Parse.Error(-1,"no user")
}
});

and in anthor function:

Parse.Cloud.define("funB", async function (request) {
    var user  = request.user;
    return Parse.Cloud.run("funA", {}, {sessionToken: user.getSessionToken()})
});

and in android app, i login a user, and call funB, but return a error, no user . why ?

I’m not sure what’s causing this, but I’d suggest that you change the way you’re doing things. Using the Parse.Cloud.run function makes an uncessary network request (unless you have directAccess enabled). What’s more is that, if you look at the request, you’ll see that the reqeust is different from your originating request.

So, I’d recomment you pull that function out into a separate file. This way, you can call it like a standard backend function and chose what you expose via Parse.Cloud.define.

Here’s an example of what I mean:
In a file called something like utils.js you could do this:

export const funA = async function (user) {
    if(!user) {
       throw new Parse.Error(-1,"no user")
    }
   // Do something
})

Then in your cloud.{js, ts} file:

import * as utils from './utils';

// if you want to make funA available to the outside world:
Parse.Cloud.define("funA", utils.funA);

// then to call funA from funB:
Parse.Cloud.define("funB", async function (request) {
    var user  = request.user;
    return utils.funA(user);
})

I hope this helps.

Yes, you are right. This is a method of last resort