Manually changing email verification status
#
Mark email as verifiedTo manually mark an email as verified, you need to first create an email verification token for the user and then use the token to verify the user's email.
- NodeJS
- GoLang
- Python
- Other Frameworks
Important
import EmailVerification from "supertokens-node/recipe/emailverification";
import supertokens from "supertokens-node";
async function manuallyVerifyEmail(recipeUserId: supertokens.RecipeUserId) {
try {
// Create an email verification token for the user
const tokenRes = await EmailVerification.createEmailVerificationToken("public", recipeUserId);
// If the token creation is successful, use the token to verify the user's email
if (tokenRes.status === "OK") {
await EmailVerification.verifyEmailUsingToken("public", tokenRes.token);
}
} catch (err) {
console.error(err);
}
}
import (
"github.com/supertokens/supertokens-golang/recipe/emailverification"
)
func main() {
userID := "..."
// Create an email verification token for the user
tokenRes, err := emailverification.CreateEmailVerificationToken("public", userID, nil)
if err != nil {
// handle error
}
// If the token creation is successful, use the token to verify the user's email
if tokenRes.OK != nil {
_, err := emailverification.VerifyEmailUsingToken("public", tokenRes.OK.Token)
if err != nil {
// handle error
}
}
}
- Asyncio
- Syncio
from supertokens_python.recipe.emailverification.asyncio import create_email_verification_token, verify_email_using_token
from supertokens_python.recipe.emailverification.interfaces import CreateEmailVerificationTokenOkResult
from supertokens_python.types import RecipeUserId
async def manually_verify_email(recipe_user_id: RecipeUserId):
try:
# Create an email verification token for the user
token_res = await create_email_verification_token("public", recipe_user_id)
# If the token creation is successful, use the token to verify the user's email
if isinstance(token_res, CreateEmailVerificationTokenOkResult):
await verify_email_using_token("public", token_res.token)
except Exception as e:
print(e)
from supertokens_python.recipe.emailverification.syncio import create_email_verification_token, verify_email_using_token
from supertokens_python.recipe.emailverification.interfaces import CreateEmailVerificationTokenOkResult
from supertokens_python.types import RecipeUserId
def manually_verify_email(recipe_user_id: RecipeUserId):
try:
# Create an email verification token for the user
token_res = create_email_verification_token("public", recipe_user_id)
# If the token creation is successful, use the token to verify the user's email
if isinstance(token_res, CreateEmailVerificationTokenOkResult):
verify_email_using_token("public", token_res.token)
except Exception as e:
print(e)
Multi Tenancy
Notice that the first argument of the function call above is "public"
. This refers to the "public"
tenantId (which is the defauld tenantId). In case you are using our multi tenancy feature, you can still pass in the "public"
tenant ID here even if the user ID is not part of that tenant because we are creating and consuming the token in one shot.
#
Mark email as unverifiedTo manually mark an email as unverified, you need to first retrieve the user's email address and then update their email verification status in the database.
- NodeJS
- GoLang
- Python
- Other Frameworks
Important
import EmailVerification from "supertokens-node/recipe/emailverification";
import supertokens from "supertokens-node";
async function manuallyUnverifyEmail(recipeUserId: supertokens.RecipeUserId) {
try {
// Set email verification status to false
await EmailVerification.unverifyEmail(recipeUserId);
} catch (err) {
console.error(err);
}
}
import (
"github.com/supertokens/supertokens-golang/recipe/emailverification"
)
func main() {
userID := "..."
// Set email verification status to false
_, err := emailverification.UnverifyEmail(userID, nil)
if err != nil {
// handle error
}
}
- Asyncio
- Syncio
from supertokens_python.recipe.emailverification.asyncio import unverify_email
from supertokens_python.types import RecipeUserId
async def manually_unverify_email(recipe_user_id: RecipeUserId):
try:
# Set email verification status to false
await unverify_email(recipe_user_id)
except Exception as e:
print(e)
from supertokens_python.recipe.emailverification.syncio import unverify_email
from supertokens_python.types import RecipeUserId
def manually_unverify_email(recipe_user_id: RecipeUserId):
try:
# Set email verification status to false
unverify_email(recipe_user_id)
except Exception as e:
print(e)
Multi Tenancy
For a multi tenant setup, the function above does not take a tenant ID since a user ID and their email verification status is unique on an app level (and not a tenant level).