Manually generating a link
You can use our backend SDK to generate the email verification link as shown below:
- NodeJS
- GoLang
- Python
- Other Frameworks
Important
For other backend frameworks, you can follow our guide on how to spin up a separate server configured with the SuperTokens backend SDK to authenticate requests and issue session tokens.
import EmailVerification from "supertokens-node/recipe/emailverification";
async function createEmailVerificationEmail(userId: string, email: string) {
try {
// Create an email verification link for the user
const linkResponse = await EmailVerification.createEmailVerificationLink(userId, email);
if (linkResponse.status === "OK") {
console.log(linkResponse.link);
} else {
// user's email is already verified
}
} catch (err) {
console.error(err);
}
}
import (
"github.com/supertokens/supertokens-golang/recipe/emailverification"
)
func main() {
userID := "..."
email := "..."
// Create an email verification link for the user
linkRes, err := emailverification.CreateEmailVerificationLink(userID, &email)
if err != nil {
// handle error
}
if linkRes.OK != nil {
link := linkRes.link
fmt.Println(link)
} else {
// user's email is already verified.
}
}
- Asyncio
- Syncio
from supertokens_python.recipe.emailverification.asyncio import create_email_verification_link, verify_email_using_token
from supertokens_python.recipe.emailverification.interfaces import CreateEmailVerificationTokenOkResult
async def send_email_verification_email(user_id: str, email: str):
try:
# Create an email verification link for the user
link_res = await create_email_verification_link(user_id, email)
if isinstance(token_res, CreateEmailVerificationTokenOkResult):
link = link_res.link
print(link)
else:
# user's email is already verified
from supertokens_python.recipe.emailverification.syncio import create_email_verification_token, create_email_verification_link
from supertokens_python.recipe.emailverification.interfaces import CreateEmailVerificationTokenOkResult
def send_email_verification_email(user_id: str, email: str):
try:
# Create an email verification link for the user
link_res = create_email_verification_link(user_id, email)
if isinstance(token_res, CreateEmailVerificationTokenOkResult):
link = link_res.link
print(link)
else:
# user's email is already verified
Multi Tenancy
For a multi tenant setup, you can pass in the user's tenantId to the createEmailVerificationLink
function as well. The generated link will use the configured websiteDomain
, however, you can change the domain of the generated link to match that of the tenant ID.