Skip to content

Commit

Permalink
fixes ev recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Nov 22, 2023
1 parent b649c69 commit 5044a1a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
9 changes: 8 additions & 1 deletion recipe/emailverification/api/implementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,20 @@ func MakeAPIImplementation() evmodels.APIInterface {
ID: userID,
Email: email.OK.Email,
}
emailVerificationURL := GetEmailVerifyLink(

emailVerificationURL, err := GetEmailVerifyLink(
options.AppInfo,
response.OK.Token,
options.RecipeID,
sessionContainer.GetTenantIdWithContext(userContext),
options.Req,
userContext,
)

if err != nil {
return evmodels.GenerateEmailVerifyTokenPOSTResponse{}, err
}

supertokens.LogDebugMessage(fmt.Sprintf("Sending email verification email to %s", email.OK.Email))
err = (*options.EmailDelivery.IngredientInterfaceImpl.SendEmail)(emaildelivery.EmailType{
EmailVerification: &emaildelivery.EmailVerificationType{
Expand Down
11 changes: 8 additions & 3 deletions recipe/emailverification/api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ package api

import (
"fmt"
"net/http"

"github.com/supertokens/supertokens-golang/supertokens"
)

func GetEmailVerifyLink(appInfo supertokens.NormalisedAppinfo, token string, recipeID string, tenantId string) string {
func GetEmailVerifyLink(appInfo supertokens.NormalisedAppinfo, token string, recipeID string, tenantId string, request *http.Request, userContext supertokens.UserContext) (string, error) {
websiteDomain, err := appInfo.GetOrigin(request, userContext)
if err != nil {
return "", err
}
return fmt.Sprintf(
"%s%s/verify-email?token=%s&rid=%s&tenantId=%s",
appInfo.WebsiteDomain.GetAsStringDangerous(),
websiteDomain.GetAsStringDangerous(),
appInfo.WebsiteBasePath.GetAsStringDangerous(),
token,
recipeID,
tenantId,
)
), nil
}
8 changes: 7 additions & 1 deletion recipe/emailverification/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,15 @@ func CreateEmailVerificationLink(tenantId string, userID string, email *string,
}, nil
}

link, err := api.GetEmailVerifyLink(st.AppInfo, emailVerificationTokenResponse.OK.Token, instance.RecipeModule.GetRecipeID(), tenantId, supertokens.GetRequestFromUserContext(userContext[0]), userContext[0])

if err != nil {
return evmodels.CreateEmailVerificationLinkResponse{}, err
}

return evmodels.CreateEmailVerificationLinkResponse{
OK: &struct{ Link string }{
Link: api.GetEmailVerifyLink(st.AppInfo, emailVerificationTokenResponse.OK.Token, instance.RecipeModule.GetRecipeID(), tenantId),
Link: link,
},
}, nil
}
Expand Down

0 comments on commit 5044a1a

Please sign in to comment.