@@ -20,6 +20,7 @@ import (
2020
2121 "github.com/supertokens/supertokens-golang/ingredients/emaildelivery"
2222 "github.com/supertokens/supertokens-golang/ingredients/smsdelivery"
23+ "github.com/supertokens/supertokens-golang/recipe/emailverification"
2324 "github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels"
2425 "github.com/supertokens/supertokens-golang/recipe/session"
2526 "github.com/supertokens/supertokens-golang/recipe/session/sessmodels"
@@ -44,6 +45,22 @@ func MakeAPIImplementation() plessmodels.APIInterface {
4445
4546 user := response .OK .User
4647
48+ if user .Email != nil {
49+ evInstance := emailverification .GetRecipeInstance ()
50+ if evInstance != nil {
51+ tokenResponse , err := (* evInstance .RecipeImpl .CreateEmailVerificationToken )(user .ID , * user .Email , userContext )
52+ if err != nil {
53+ return plessmodels.ConsumeCodePOSTResponse {}, err
54+ }
55+ if tokenResponse .OK != nil {
56+ _ , err := (* evInstance .RecipeImpl .VerifyEmailUsingToken )(tokenResponse .OK .Token , userContext )
57+ if err != nil {
58+ return plessmodels.ConsumeCodePOSTResponse {}, err
59+ }
60+ }
61+ }
62+ }
63+
4764 session , err := session .CreateNewSessionWithContext (options .Res , user .ID , map [string ]interface {}{}, map [string ]interface {}{}, userContext )
4865 if err != nil {
4966 return plessmodels.ConsumeCodePOSTResponse {}, err
@@ -63,6 +80,10 @@ func MakeAPIImplementation() plessmodels.APIInterface {
6380 }
6481
6582 createCodePOST := func (email * string , phoneNumber * string , options plessmodels.APIOptions , userContext supertokens.UserContext ) (plessmodels.CreateCodePOSTResponse , error ) {
83+ stInstance , err := supertokens .GetInstanceOrThrowError ()
84+ if err != nil {
85+ return plessmodels.CreateCodePOSTResponse {}, err
86+ }
6687
6788 var userInputCodeInput * string
6889 if options .Config .GetCustomUserInputCode != nil {
@@ -83,12 +104,14 @@ func MakeAPIImplementation() plessmodels.APIInterface {
83104 var userInputCode * string
84105 flowType := options .Config .FlowType
85106 if flowType == "MAGIC_LINK" || flowType == "USER_INPUT_CODE_AND_MAGIC_LINK" {
86- link , err := options .Config .GetLinkDomainAndPath (email , phoneNumber , userContext )
87- if err != nil {
88- return plessmodels.CreateCodePOSTResponse {}, err
89- }
90- link = link + "?rid=" + options .RecipeID + "&preAuthSessionId=" + response .OK .PreAuthSessionID + "#" + response .OK .LinkCode
91-
107+ link := fmt .Sprintf (
108+ "%s%s/verify?rid=%s&preAuthSessionId=%s#%s" ,
109+ stInstance .AppInfo .WebsiteDomain .GetAsStringDangerous (),
110+ stInstance .AppInfo .WebsiteBasePath .GetAsStringDangerous (),
111+ options .RecipeID ,
112+ response .OK .PreAuthSessionID ,
113+ response .OK .LinkCode ,
114+ )
92115 magicLink = & link
93116 }
94117
@@ -210,6 +233,10 @@ func MakeAPIImplementation() plessmodels.APIInterface {
210233 }
211234
212235 resendCodePOST := func (deviceID string , preAuthSessionID string , options plessmodels.APIOptions , userContext supertokens.UserContext ) (plessmodels.ResendCodePOSTResponse , error ) {
236+ stInstance , err := supertokens .GetInstanceOrThrowError ()
237+ if err != nil {
238+ return plessmodels.ResendCodePOSTResponse {}, err
239+ }
213240 deviceInfo , err := (* options .RecipeImplementation .ListCodesByDeviceID )(deviceID , userContext )
214241 if err != nil {
215242 return plessmodels.ResendCodePOSTResponse {}, err
@@ -255,11 +282,14 @@ func MakeAPIImplementation() plessmodels.APIInterface {
255282 var userInputCode * string
256283 flowType := options .Config .FlowType
257284 if flowType == "MAGIC_LINK" || flowType == "USER_INPUT_CODE_AND_MAGIC_LINK" {
258- link , err := options .Config .GetLinkDomainAndPath (deviceInfo .Email , deviceInfo .PhoneNumber , userContext )
259- if err != nil {
260- return plessmodels.ResendCodePOSTResponse {}, err
261- }
262- link = link + "?rid=" + options .RecipeID + "&preAuthSessionId=" + response .OK .PreAuthSessionID + "#" + response .OK .LinkCode
285+ link := fmt .Sprintf (
286+ "%s%s/verify?rid=%s&preAuthSessionId=%s#%s" ,
287+ stInstance .AppInfo .WebsiteDomain .GetAsStringDangerous (),
288+ stInstance .AppInfo .WebsiteBasePath .GetAsStringDangerous (),
289+ options .RecipeID ,
290+ response .OK .PreAuthSessionID ,
291+ response .OK .LinkCode ,
292+ )
263293
264294 magicLink = & link
265295 }
0 commit comments