Skip to main content

Manually changing email verification status

Mark email as verified#

To 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.

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);
}
}
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 unverified#

To 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.

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);
}
}
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).

Looking for older versions of the documentation?
Which UI do you use?
Custom UI
Pre built UI