How to initialize object when a user is created?

I have two things I would like to do when new Users are created, and Iā€™m not sure the best way:

  1. Reverse resolve their ENS name and store it on their User object. Or in other words: how to keep ens names in sync with the Moralis DB?
  2. Initialize other objects in the DB that will be associated with the User.

I was messing with the _beforeSave trigger for Users, but it was having some weird behaviors. And for the ens thing, wasnā€™t sure if using the Sync feature might be useful?

Did you try to use the resolve reverse API not entirely sure if sync is perfect for your use case as Iā€™m not entirely sure which event to sync with. But if you use our API, you can just directly use it to resolve the address to ENS real time :raised_hands:

what problems did you have with beforeSave for User class?

Okay, so I just tried setting this up again. Iā€™m basically doing:

Moralis.Cloud.beforeSave(Moralis.User, async function (request) {
  if (!request.object.id) {
   const inventory = new Inventory()
   await inventory.save()
   request.object.set('inventory', inventory);
  }
})

And Iā€™m getting the following error message:

Error: {ā€œmessageā€:ā€œSigning message has expired.ā€,ā€œcodeā€:101}

And the user isnā€™t created. I assume this is because Iā€™m "await"ing and the authenticate() call needs to happen synchronously.

And to add to this, I want to be able to do:

const user = await Moralis.authenticate()
const inventory = await user.get('inventory').fetch()

So I assume beforeSave would have been the best place for this. I believe my best option now is to create a Cloud function called ā€œfetchInventoryā€ that checks if the user has one and if not, creates it. But I would prefer to explicitly define the initial objectsā€¦