@@ -21,6 +21,8 @@ import (
2121
2222 "github.com/supertokens/supertokens-golang/ingredients/emaildelivery"
2323 "github.com/supertokens/supertokens-golang/ingredients/smsdelivery"
24+ "github.com/supertokens/supertokens-golang/recipe/emailverification"
25+ "github.com/supertokens/supertokens-golang/recipe/emailverification/evmodels"
2426 "github.com/supertokens/supertokens-golang/recipe/passwordless"
2527 "github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels"
2628 "github.com/supertokens/supertokens-golang/recipe/thirdparty"
@@ -133,6 +135,13 @@ func MakeRecipe(recipeId string, appInfo supertokens.NormalisedAppinfo, config t
133135 }
134136 }
135137
138+ supertokens .AddPostInitCallback (func () {
139+ evRecipe := emailverification .GetRecipeInstance ()
140+ if evRecipe != nil {
141+ evRecipe .AddGetEmailForUserIdFunc (r .getEmailForUserId )
142+ }
143+ })
144+
136145 return * r , nil
137146}
138147
@@ -217,25 +226,37 @@ func (r *Recipe) handleError(err error, req *http.Request, res http.ResponseWrit
217226 return false , err
218227}
219228
220- func (r * Recipe ) getEmailForUserIdForEmailVerification (userID string , userContext supertokens.UserContext ) (string , error ) {
229+ func (r * Recipe ) getEmailForUserId (userID string , userContext supertokens.UserContext ) (evmodels. TypeEmailInfo , error ) {
221230 userInfo , err := (* r .RecipeImpl .GetUserByID )(userID , userContext )
222231 if err != nil {
223- return "" , err
232+ return evmodels. TypeEmailInfo {} , err
224233 }
225234 if userInfo == nil {
226- return "" , errors .New ("Unknown User ID provided" )
235+ return evmodels.TypeEmailInfo {
236+ UnknownUserIDError : & struct {}{},
237+ }, nil
227238 }
228239 if userInfo .ThirdParty == nil {
229240 if userInfo .Email != nil {
230- return * userInfo .Email , nil
241+ return evmodels.TypeEmailInfo {
242+ OK : & struct { Email string }{
243+ Email : * userInfo .Email ,
244+ },
245+ }, nil
231246 }
232247 // this is a passwordless user with only a phone number.
233248 // returning an empty string here is not a problem since
234249 // we override the email verification functions above to
235250 // send that the email is already verified for passwordless users.
236- return "" , nil
251+ return evmodels.TypeEmailInfo {
252+ EmailDoesNotExistError : & struct {}{},
253+ }, nil
237254 }
238- return * userInfo .Email , nil
255+ return evmodels.TypeEmailInfo {
256+ OK : & struct { Email string }{
257+ Email : * userInfo .Email ,
258+ },
259+ }, nil
239260}
240261
241262func ResetForTest () {
0 commit comments