Moralis.Cloud.run is undefined

Hello.

I am trying to call one of my moralis cloud function from a firebase cloud function.

I have the following code :


const Moralis = require("moralis").default;

...


exports.testCloudfunction = functions.https.onCall(async (data, context) => {
...

  await Moralis.start({
    apiKey: moralisKey,
  });

  const checkCode = await Moralis.Cloud.run("checkGiftCode",{
      code:giftCode,
      wallet:claimAddress
    });
...

which is what i found in every docs and exemples i found, but i get the following error :

Unhandled error TypeError: Cannot read properties of undefined (reading ‘run’) at /workspace/index.js:275:39 at async /workspace/node_modules/firebase-functions/lib/common/providers/https.js:407:26

So moralis.Cloud is undefined.

What am I doing wrong?

Thanks :slight_smile:

Moralis.Cloud.run syntax is for moralis-v1 (Moralis server) usage - looks like you are using moralis v2 SDK.

You can either call the Moralis cloud function directly with HTTP requests or use moralis-v1.

Fair enough.

Is it ok to install moralis-v1 next to moralis only to use the cloud functions or should I use the v1 for everything ?

If I use the HTTP request, is there a way to safely pass authentification?
So the cloud function can verify if the person who sends the request is authenticated and which user it is.
I assume Moralis.cloud.run does that automatically?

Thanks :slight_smile:

you can also use http requests and pass the authentication parameters, session token mainly, you can look at a cloud function request in network tab of the browser to see all the info