Doing operations post email verification
To perform any task post email verification like analytics, sending a user a welcome email or notifying an internal dashboard, you'll need to override the emailVerificationFeature > verifyEmailPOST
API.
- NodeJS
- GoLang
- Python
import SuperTokens from 'supertokens-node';import ThirdPartyEmailPassword from "supertokens-node/recipe/thirdpartyemailpassword";import Session from "supertokens-node/recipe/session";
SuperTokens.init({ appInfo: { apiDomain: "...", appName: "...", websiteDomain: "..." }, recipeList: [ ThirdPartyEmailPassword.init({ override: { emailVerificationFeature: { apis: (originalImplementation) => { return { ...originalImplementation, verifyEmailPOST: async function (input) {
if (originalImplementation.verifyEmailPOST === undefined) { throw Error("Should never come here"); }
// First we call the original implementation let response = await originalImplementation.verifyEmailPOST(input);
// Then we check if it was successfully completed if (response.status === "OK") { let { id, email } = response.user; // TODO: post email verification logic } return response; } } } } } }), Session.init() ]});
import ( "fmt"
"github.com/supertokens/supertokens-golang/recipe/emailverification/evmodels" "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword" "github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword/tpepmodels" "github.com/supertokens/supertokens-golang/supertokens")
func main() { supertokens.Init(supertokens.TypeInput{ RecipeList: []supertokens.Recipe{ thirdpartyemailpassword.Init(&tpepmodels.TypeInput{ Override: &tpepmodels.OverrideStruct{ EmailVerificationFeature: &evmodels.OverrideStruct{ APIs: func(originalImplementation evmodels.APIInterface) evmodels.APIInterface { // First we create a copy of the original implementation originalVerifyEmailPOST := *originalImplementation.VerifyEmailPOST
// we override the API for verifying an email (*originalImplementation.VerifyEmailPOST) = func(token string, options evmodels.APIOptions, userContext supertokens.UserContext) (evmodels.VerifyEmailPOSTResponse, error) {
// First we call the original implementation resp, err := originalVerifyEmailPOST(token, options, userContext)
if err != nil { return evmodels.VerifyEmailPOSTResponse{}, err }
if resp.OK != nil { // contains the user's ID and email user := resp.OK.User fmt.Println(user)
// TODO: post email verification logic }
return resp, nil }
return originalImplementation }, }, }, }), }, })}
from supertokens_python import init, InputAppInfofrom supertokens_python.recipe import thirdpartyemailpasswordfrom supertokens_python.recipe.emailverification import InputOverrideConfig as EVInputOverrideConfigfrom supertokens_python.recipe.emailverification.interfaces import APIInterface, APIOptions, EmailVerifyPostOkResultfrom typing import Dict, Any
def override_email_verification_apis(original_implementation_email_verification: APIInterface): original_email_verify_post = original_implementation_email_verification.email_verify_post
async def email_verify_post(token: str, api_options: APIOptions, user_context: Dict[str, Any]): response = await original_email_verify_post(token, api_options, user_context)
# Then we check if it was successfully completed if isinstance(response, EmailVerifyPostOkResult): _ = response.user # TODO: post email verification logic return response
original_implementation_email_verification.email_verify_post = email_verify_post return original_implementation_email_verification
init( app_info=InputAppInfo(api_domain="...", app_name="...", website_domain="..."), framework='...', recipe_list=[ thirdpartyemailpassword.init( override=thirdpartyemailpassword.InputOverrideConfig( email_verification_feature=EVInputOverrideConfig( apis=override_email_verification_apis ) ) ) ])