User email verification sent twice

Hello,

I’m implementing the auth verification email feature using Sendgrid integration and I’m facing the following issue: the email is sent twice, first one without any values populated (link and name) and second one with these values properly populated and a functioning link.

Front-end code (called from a form submit)

    const handleSignupSubmit = async (event: SyntheticEvent) => {
        ....
        ....
        try {
            await signup(username, password, email); // react-moralis signup
            await Moralis.Cloud.run('sendUserVerificationEmail', { name: username });
        } catch (error) {
            console.log(`${error instanceof Error && error.message}`);
        }
    };

I know you provide an alternative to Moralis.Cloud.run in react-moralis but I’d rather use the pure-JS API

Cloud function code (only called once as expected (according to the logs))

Moralis.Cloud.define('sendUserVerificationEmail', (request) => {
    const logger = Moralis.Cloud.getLogger();

    logger.info(`sendUserVerificationEmail: ${JSON.stringify(request)}`);

    Moralis.Cloud.sendEmail({
        to: request.user.get('email'),
        templateId: 'd-d8....42',
        dynamic_template_data: { name: request.params.name },
    });
});

Emails received (I’ve hidden some data on purpose):

Thanks in advance for your help on this :pray:

If you don’t call that cloud function, you receive only one email?

Indeed! Did I miss something here? BTW I don’t see any logs related to my cloud function call

An email will be sent automatically when the email is set for a user

So I don’t need to define any cloud functions for this? No access to any logs also?

No logs from what I know

Got it! Last question: if I don’t have to run my cloud function, how can I pass down extra parameters to be forwarded to Sendgrid? (like name in my example)

I think that you would have to make your own implementation of sending it if you want to customise it, I think that you will find another post that shares how it was done

You can also think about self hosting parse server depending on what functionalities you are using now from the server

1 Like