Skip to content

Commit 5ed99e0

Browse files
Merge pull request #215 from supertokens/sendEmail-bug-emailpassword
fix: sendEmail override issue
2 parents 6e89720 + 9d259a2 commit 5ed99e0

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
## [0.9.10]
11+
- Fixes issue where if SendEmail is overridden with a different email, it will reset that email.
12+
1013
## [0.9.9] - 2022-11-24
1114

1215
### Added:

recipe/emailpassword/emaildelivery/backwardCompatibilityService/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ func MakeBackwardCompatibilityService(recipeInterfaceImpl epmodels.RecipeInterfa
3434
if user == nil {
3535
return errors.New("should never come here")
3636
}
37+
38+
// we add this here cause the user may have overridden the sendEmail function
39+
// to change the input email and if we don't do this, the input email
40+
// will get reset by the getUserById call above.
41+
user.Email = input.PasswordReset.User.Email
3742
sendResetPasswordEmail(*user, input.PasswordReset.PasswordResetLink, userContext)
3843
} else {
3944
return errors.New("should never come here")

recipe/emailpassword/emailpassword_email_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,39 @@ func TestDefaultBackwardCompatibilityPasswordResetForEmailPasswordUser(t *testin
4848
assert.NotEmpty(t, PasswordResetDataForTest.PasswordResetURLWithToken)
4949
}
5050

51+
func TestDefaultBackwardCompatibilityPasswordResetForEmailPasswordUserWithSendEmailOverride(t *testing.T) {
52+
BeforeEach()
53+
unittesting.StartUpST("localhost", "8080")
54+
defer AfterEach()
55+
56+
testServer := supertokensInitForTest(t,
57+
session.Init(nil),
58+
Init(&epmodels.TypeInput{
59+
EmailDelivery: &emaildelivery.TypeInput{
60+
Override: func(originalImplementation emaildelivery.EmailDeliveryInterface) emaildelivery.EmailDeliveryInterface {
61+
oSendEmail := *originalImplementation.SendEmail
62+
nSendEmail := func(input emaildelivery.EmailType, userContext supertokens.UserContext) error {
63+
input.PasswordReset.User.Email = "[email protected]"
64+
return oSendEmail(input, userContext)
65+
}
66+
67+
*originalImplementation.SendEmail = nSendEmail
68+
return originalImplementation
69+
},
70+
},
71+
}),
72+
)
73+
defer testServer.Close()
74+
75+
SignUp("[email protected]", "1234abcd")
76+
resp, err := unittesting.PasswordResetTokenRequest("[email protected]", testServer.URL)
77+
assert.NoError(t, err)
78+
assert.Equal(t, http.StatusOK, resp.StatusCode)
79+
assert.True(t, PasswordResetEmailSentForTest)
80+
assert.Equal(t, PasswordResetDataForTest.User.Email, "[email protected]")
81+
assert.NotEmpty(t, PasswordResetDataForTest.PasswordResetURLWithToken)
82+
}
83+
5184
func TestDefaultBackwardCompatibilityPasswordResetForNonExistantUser(t *testing.T) {
5285
BeforeEach()
5386
unittesting.StartUpST("localhost", "8080")

supertokens/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
)
2222

2323
// VERSION current version of the lib
24-
const VERSION = "0.9.9"
24+
const VERSION = "0.9.10"
2525

2626
var (
2727
cdiSupported = []string{"2.8", "2.9", "2.10", "2.11", "2.12", "2.13", "2.14", "2.15"}

0 commit comments

Comments
 (0)