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
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 manuallyVerifyEmail(userId: string) {
try {
// Create an email verification token for the user
const tokenRes = await EmailVerification.createEmailVerificationToken(userId);
// If the token creation is successful, use the token to verify the user's email
if (tokenRes.status === "OK") {
await EmailVerification.verifyEmailUsingToken(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(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(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
async def manually_verify_email(user_id: str):
try:
# Create an email verification token for the user
token_res = await create_email_verification_token(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(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
def manually_verify_email(user_id: str):
try:
# Create an email verification token for the user
token_res = create_email_verification_token(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(token_res.token)
except Exception as e:
print(e)
#
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
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 manuallyUnverifyEmail(userId: string) {
try {
// Set email verification status to false
await EmailVerification.unverifyEmail(userId);
} 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
async def manually_unverify_email(user_id: str):
try:
# Set email verification status to false
await unverify_email(user_id)
except Exception as e:
print(e)
from supertokens_python.recipe.emailverification.syncio import unverify_email
def manually_unverify_email(user_id: str):
try:
# Set email verification status to false
unverify_email(user_id)
except Exception as e:
print(e)