Cloud Function error - does not work afterSave for Moralis.User

Hey guys
I am going to add new row in customized NftUser class when added new row in User class.
So I wrote the cloud function as follow:

Moralis.Cloud.afterSave(Moralis.User, async (request) => {
    const logger = Moralis.Cloud.getLogger();
    logger.info("added new user"); 
})

But it does not work.
What should I do?

https://docs.moralis.io/moralis-server/cloud-code/triggers#consequences-for-triggers
code looks like this:

Moralis.Cloud.afterSave("EthTransactions", async function(request) {
  const confirmed = request.object.get("confirmed");
  if (confirmed) {
    // do something
  } else {
    // handle unconfirmed case
  }
});

Hey @cryptokid
Thanks for your reply.
https://docs.moralis.io/moralis-server/cloud-code/triggers#aftersave
But for PREDEFINED CLASSES, we should not pass a string for the first argument. Instead, we should pass the class itself, for example:

Moralis.Cloud.afterSave(Moralis.User, async (request) => {
    // code here
})

User class is the predefined class. right?

1 Like

Hey @yuki

Try to use it this way:

Moralis.Cloud.afterSave("Users", async (request) => {
    // code here
})

did anyone get this working?
afterSave trigger still not working for User class for me regardless of if I use:

Moralis.Cloud.afterSave(Moralis.User, async (request) => {
    // code here
})

or

Moralis.Cloud.afterSave("User", async (request) => {
    // code here
})

any help would be appreciated

it didn’t work last time I checked either, I think that it doesn’t work because afterSave for User class is used internally on Moralis server, you could try to use beforeSave for User Class instead of afterSave

fyi beforeSave is working for me.
afterSave still not working.
thanks.

1 Like