[SOLVED] - How to get signin message in cloud function

Hello,

I have found plenty of doc on how to customize my signin message.
But nothing on how to access it inside a cloud function.

Anyone could help me with that ?

I am trying to get referral data for users when they log in (the referral data is passed on the signin message).

So i was thinking of doing an afterSave trigger on the _User class, catch the user, check if i already know him and if not, get the signin message and see if the user has a referral or not and then log the user in my class.

Thanks :slight_smile:

I donโ€™t understand what you mean. Maybe you can rephrase the question?

so when a user logs in, i pass the following signin message :

await authenticate({signingMessage: `Loggin to starseed gift app via moralis. Ref=${refferral}` })

The goal is to collect eventual referral user of the user loggin in.

So i want to create a cloud function that triggers when a user logs in, check in my own class if that user already has a referal.
If so nothing happen.
But if the user doesnt have a referral yet, then i want to check the signin message to verify if their is one now and if so, log that into my class.

Hope that make sens :slight_smile:

I made that function that works fine :

Moralis.Cloud.beforeSave(
  Moralis.User,
  async (request) => {
    // code here
    logger.info("user try to loggin")
    const tokenId = request.object.get("ethAddress");
    logger.info(tokenId)
  }
  // Validation Object or Validation Function
);

So back to the first question :

  • how do i get the signin message for that user ?

ok, it should be easy, there is authData column that has that signed message data

you may have to use afterSave if beforeSave doesnโ€™t work

you can also use logger.info(JSON.stringify(request)) to see all the data`

That did it, I found it in request.object.authData.moralisEth.data :


    const authtData = request.object.get("authData");
    logger.info(authtData)
    logger.info(authtData.moralisEth.data)
    const signMessage = authtData.moralisEth.data

Thanks a lot :slight_smile:

1 Like