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
import EmailVerification from "supertokens-node/recipe/emailverification";
import supertokens from "supertokens-node";
async function createEmailVerificationLink(recipeUserId: supertokens.RecipeUserId, email: string) {
try {
// Create an email verification link for the user
const linkResponse = await EmailVerification.createEmailVerificationLink("public", recipeUserId, email);
if (linkResponse.status === "OK") {
console.log(linkResponse.link);
} else {
// user's email is already verified
}
} catch (err) {
console.error(err);
}
}
import (
"fmt"
"github.com/supertokens/supertokens-golang/recipe/emailverification"
)
func main() {
userID := "..."
email := "..."
// Create an email verification link for the user
linkRes, err := emailverification.CreateEmailVerificationLink("public", userID, &email)
if err != nil {
// handle error
}
if linkRes.OK != nil {
link := linkRes.OK.Link
fmt.Println(link)
} else {
// user's email is already verified.
}
}
- Asyncio
- Syncio
from supertokens_python.recipe.emailverification.asyncio import create_email_verification_link
from supertokens_python.recipe.emailverification.interfaces import CreateEmailVerificationLinkOkResult
async def create_link(user_id: str, email: str):
# Create an email verification link for the user
link_res = await create_email_verification_link("public", user_id, email)
if isinstance(link_res, CreateEmailVerificationLinkOkResult):
link = link_res.link
print(link)
else:
print("user's email is already verified")
from supertokens_python.recipe.emailverification.syncio import create_email_verification_link
from supertokens_python.recipe.emailverification.interfaces import CreateEmailVerificationLinkOkResult
def create_link(user_id: str, email: str):
# Create an email verification link for the user
link_res = create_email_verification_link("public", user_id, email)
if isinstance(link_res, CreateEmailVerificationLinkOkResult):
link = link_res.link
print(link)
else:
print("user's email is already verified")
Multi Tenancy
Notice that the first argument to the function call above is "public"
. This refers to the default tenant ID that is used in SuperTokens. It means that the generated email verification link can only be consumed by users belonging to the "public"
tenant.
If you are using our multi tenancy feature, you can pass in the tenantId that contains this user, which you can fetch by getting the user object for this userId.
Finally, the generated link will use the configured websiteDomain
from the appInfo
object (in supertokens.init
), however, you can change the domain of the generated link to match that of the tenant ID.