Hi, is it possible to trigger sending the email ve...
# support-questions-legacy
f
Hi, is it possible to trigger sending the email verification mail through the backend sdks?
r
Hey!
Yes it is. There should be a function to generate an email verification token and another function to send the email with that token. Which recipe are you using?
f
thirdpartyemailpassword
With the nodejs backend ask
Sdk
I've overwritten the sendEmail function for reset password mail and email verfication mail to send a custom mail... I was using
sendVerificationMail
on the frontend to trigger the send mail function, but I would like to trigger it in the backend within an api handler.
The usecase is: I wan't to send a email verification mail after the user has completed the other custom auth stuff (in my case, setting a username...)
r
Copy code
ts
let userInfo = await ThirdPartyEmailPassword.getUserById("<userId>");
if (userInfo !== undefined) {
    let resp = await ThirdPartyEmailPassword.createEmailVerificationToken(userInfo.id);
    if (resp.status === "OK") {
        let token = resp.token;
        await ThirdPartyEmailPassword.sendEmail({
            // you can use your own websiteDomain / websiteBasePath
            emailVerifyLink: `http://localhost:3000/auth/verify-email?token=${token}&rid=thirdpartyemailpassword`,
            type: "EMAIL_VERIFICATION",
            user: {
                email: userInfo.email,
                id: userInfo.id
            },
            userContext: {} // this doesn't matter
        })
    }
}
f
Alright, thanks a lot.... However, I wonder what the fronentSdk exactly does... because maybe it's more efficient to just do the same thing the
sendVerificationMail
does on the backend.
r
that function calls the API on the backend that sends the email verification email. You can see the logic of that API here: https://github.com/supertokens/supertokens-node/blob/master/lib/ts/recipe/emailverification/api/implementation.ts#L51 It's pretty much the same thing as the above code.
f
Yes will implement the above code! Thanks for the most amazing support ❤️
r
happy to help :0
🙂 *
19 Views