[SOLVED] - How to get the link to verify user email

Hello everyone.

I am trying to make a function to send user a verification email.
The process to setup the email or creat send grid templates is well documented but I have found absolutly nothing on how to get or build the link I am suppose to pass to the template.

Here is the doc :

I guess I could extrapolate something for the tutorial, at some point i can see the link in the browser…
But it doesnt seem like the propper way to go.

Also found a forum mentionning :

await Moralis.User.requestEmailVerification(email)

But i couldnt make that work (my email config is setup) so it might be outdated :


  logger.info(`user email is ${email}`)

  await Moralis.User.requestEmailVerification(email)
  .then((result) => {
    logger.info(`all good ${JSON.stringify(result)}`)
    
  }).catch((err) => {
    logger.info(`oh no !!! ${err}`)
    
  });

The email logged is correct, the function goes into the then so no errors but the result is an empty object no email in my inbox (all folders checked)

Any help would be welcome :slight_smile:

Thanks

By the way. I doing that in a cloud function because I read somewhere that sending email should be done in the backend.

But im fine with a front end solution.

I am using the react-moralis modules in my frontend but havnt seen anything about email verification there as well.

you should not do anything, an email should be sent automatically to the email of a user when it is added to User table

I assume this is the case if I use the login with email and password solution ?

In my case, users logs in with their metamask but we have a way for them to set an email to get a higher user verification tier.

Setting the email was easy. Now i just want a button to trigger an email verification when the user clicks on it.

I can see that most exemples uses :
currentUser = Moralis.User.current();

while my user comes from the request :
currentUser = request.user

const user = Moralis.User.current() ==> return null form me.

Is there a way for me to initialize the moralis user with my user and then get the verification link from that ?

Ok, I made progress thanks to this post :

Now the email is sent but i get :
image

and the resend link is :

Im gonna take a closer look at the link but its on the good way :slight_smile:

The link passes the email as the userName. I guess this is the problem as my user do not have a username defined

Alright, so it seems to work if i also set the username with the email address.

Then my verif link goes to :

Hope it might help others :slight_smile:

1 Like