Skip to content

Commit efa8a47

Browse files
Merge pull request #312 from supertokens/fix/dashboard-update-password
fix: Fix issue with dashboard throwing an error when updating the user's password
2 parents 866de13 + a205201 commit efa8a47

File tree

7 files changed

+197
-12
lines changed

7 files changed

+197
-12
lines changed

CHANGELOG.md

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

88
## [unreleased]
99

10+
## [0.12.9] - 2023-07-26
11+
12+
- Fixes an issue where updating the user's password from the user management dashboard would result in a crash when using the thirdpartyemailpassword recipe (https://github.com/supertokens/supertokens-golang/issues/311)
13+
1014
## [0.12.8] - 2023-07-10
1115

1216
- Adds additional tests for session verification

recipe/dashboard/api/userdetails/userPasswordPut.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ func UserPasswordPut(apiInterface dashboardmodels.APIInterface, options dashboar
126126
}, nil
127127
}
128128

129-
var passwordField epmodels.TypeInputFormField
129+
var passwordField epmodels.NormalisedFormField
130130

131-
for _, value := range thirdpartyemailpassword.GetRecipeInstance().Config.SignUpFeature.FormFields {
131+
for _, value := range thirdpartyemailpassword.GetRecipeInstance().GetEmailPasswordRecipe().Config.SignUpFeature.FormFields {
132132
if value.ID == "password" {
133133
passwordField = value
134134
}

recipe/dashboard/api/userdetails/userPut.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ func updateEmailForRecipeId(recipeId string, userId string, email string) (updat
9696
}
9797

9898
if recipeId == "thirdpartyemailpassword" {
99-
var emailField epmodels.TypeInputFormField
99+
var emailField epmodels.NormalisedFormField
100100

101-
for _, value := range thirdpartyemailpassword.GetRecipeInstance().Config.SignUpFeature.FormFields {
101+
for _, value := range thirdpartyemailpassword.GetRecipeInstance().GetEmailPasswordRecipe().Config.SignUpFeature.FormFields {
102102
if value.ID == "email" {
103103
emailField = value
104104
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package dashboard
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
6+
"github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword"
7+
"github.com/supertokens/supertokens-golang/supertokens"
8+
"github.com/supertokens/supertokens-golang/test/unittesting"
9+
"net/http"
10+
"net/http/httptest"
11+
"strings"
12+
"testing"
13+
)
14+
15+
/**
16+
- Initialise with thirdpartyemailpassword and provide no custom form fields
17+
- Create an emailpassword user using the thirdpartyemailpassword recipe
18+
- Try to change the password of the user
19+
- Should result in no errors
20+
- Sign in with new password
21+
- Should result in no errors and same user should be returned
22+
*/
23+
func TestThatUpdatingPasswordWithNoSignUpFeatureInTPEPWorks(t *testing.T) {
24+
config := supertokens.TypeInput{
25+
OnSuperTokensAPIError: func(err error, req *http.Request, res http.ResponseWriter) {
26+
print(err)
27+
},
28+
Supertokens: &supertokens.ConnectionInfo{
29+
ConnectionURI: "http://localhost:8080",
30+
},
31+
AppInfo: supertokens.AppInfo{
32+
APIDomain: "api.supertokens.io",
33+
AppName: "SuperTokens",
34+
WebsiteDomain: "supertokens.io",
35+
},
36+
RecipeList: []supertokens.Recipe{
37+
thirdpartyemailpassword.Init(nil),
38+
Init(&dashboardmodels.TypeInput{
39+
ApiKey: "testapikey",
40+
}),
41+
},
42+
}
43+
44+
BeforeEach()
45+
unittesting.StartUpST("localhost", "8080")
46+
defer AfterEach()
47+
err := supertokens.Init(config)
48+
if err != nil {
49+
t.Error(err.Error())
50+
}
51+
52+
mux := http.NewServeMux()
53+
testServer := httptest.NewServer(supertokens.Middleware(mux))
54+
defer testServer.Close()
55+
56+
signupResponse, err := thirdpartyemailpassword.EmailPasswordSignUp("testing@supertokens.com", "abcd1234")
57+
if err != nil {
58+
t.Error(err.Error())
59+
}
60+
61+
assert.NotNil(t, signupResponse.OK)
62+
63+
userId := signupResponse.OK.User.ID
64+
65+
req, err := http.NewRequest(http.MethodPut, testServer.URL+"/auth/dashboard/api/user/password", strings.NewReader(`{"userId": "`+userId+`", "newPassword": "newabcd1234"}`))
66+
67+
if err != nil {
68+
t.Error(err.Error())
69+
}
70+
71+
req.Header.Set("Authorization", "Bearer testapikey")
72+
res, err := http.DefaultClient.Do(req)
73+
74+
if err != nil {
75+
t.Error(err.Error())
76+
}
77+
78+
assert.Equal(t, http.StatusOK, res.StatusCode)
79+
80+
signInResponse, err := thirdpartyemailpassword.EmailPasswordSignIn("testing@supertokens.com", "newabcd1234")
81+
82+
if err != nil {
83+
t.Error(err.Error())
84+
}
85+
86+
assert.NotNil(t, signInResponse.OK)
87+
assert.Equal(t, signInResponse.OK.User.ID, userId)
88+
}

recipe/dashboard/userPut_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package dashboard
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
6+
"github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword"
7+
"github.com/supertokens/supertokens-golang/supertokens"
8+
"github.com/supertokens/supertokens-golang/test/unittesting"
9+
"net/http"
10+
"net/http/httptest"
11+
"strings"
12+
"testing"
13+
)
14+
15+
/**
16+
- Initialise with thirdpartyemailpassword and provide no custom form fields
17+
- Create an emailpassword user using the thirdpartyemailpassword recipe
18+
- Try to change the password of the user
19+
- Should result in no errors
20+
- Sign in with new password
21+
- Should result in no errors and same user should be returned
22+
*/
23+
func TestThatUpdatingEmailWithNoSignUpFeatureInTPEPWorks(t *testing.T) {
24+
config := supertokens.TypeInput{
25+
OnSuperTokensAPIError: func(err error, req *http.Request, res http.ResponseWriter) {
26+
print(err)
27+
},
28+
Supertokens: &supertokens.ConnectionInfo{
29+
ConnectionURI: "http://localhost:8080",
30+
},
31+
AppInfo: supertokens.AppInfo{
32+
APIDomain: "api.supertokens.io",
33+
AppName: "SuperTokens",
34+
WebsiteDomain: "supertokens.io",
35+
},
36+
RecipeList: []supertokens.Recipe{
37+
thirdpartyemailpassword.Init(nil),
38+
Init(&dashboardmodels.TypeInput{
39+
ApiKey: "testapikey",
40+
}),
41+
},
42+
}
43+
44+
BeforeEach()
45+
unittesting.StartUpST("localhost", "8080")
46+
defer AfterEach()
47+
err := supertokens.Init(config)
48+
if err != nil {
49+
t.Error(err.Error())
50+
}
51+
52+
mux := http.NewServeMux()
53+
testServer := httptest.NewServer(supertokens.Middleware(mux))
54+
defer testServer.Close()
55+
56+
signupResponse, err := thirdpartyemailpassword.EmailPasswordSignUp("testing@supertokens.com", "abcd1234")
57+
if err != nil {
58+
t.Error(err.Error())
59+
}
60+
61+
assert.NotNil(t, signupResponse.OK)
62+
63+
userId := signupResponse.OK.User.ID
64+
65+
req, err := http.NewRequest(http.MethodPut, testServer.URL+"/auth/dashboard/api/user", strings.NewReader(`{"userId": "`+userId+`", "firstName": "", "lastName": "", "phone": "", "email": "testing2@supertokens.com", "recipeId": "emailpassword"}`))
66+
67+
if err != nil {
68+
t.Error(err.Error())
69+
}
70+
71+
req.Header.Set("Authorization", "Bearer testapikey")
72+
res, err := http.DefaultClient.Do(req)
73+
74+
if err != nil {
75+
t.Error(err.Error())
76+
}
77+
78+
assert.Equal(t, http.StatusOK, res.StatusCode)
79+
80+
signInResponse, err := thirdpartyemailpassword.EmailPasswordSignIn("testing2@supertokens.com", "abcd1234")
81+
82+
if err != nil {
83+
t.Error(err.Error())
84+
}
85+
86+
assert.NotNil(t, signInResponse.OK)
87+
assert.Equal(t, signInResponse.OK.User.ID, userId)
88+
}

recipe/thirdpartyemailpassword/recipe.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ import (
3434
const RECIPE_ID = "thirdpartyemailpassword"
3535

3636
type Recipe struct {
37-
RecipeModule supertokens.RecipeModule
38-
Config tpepmodels.TypeNormalisedInput
39-
emailPasswordRecipe *emailpassword.Recipe
40-
thirdPartyRecipe *thirdparty.Recipe
41-
RecipeImpl tpepmodels.RecipeInterface
42-
APIImpl tpepmodels.APIInterface
43-
EmailDelivery emaildelivery.Ingredient
37+
RecipeModule supertokens.RecipeModule
38+
Config tpepmodels.TypeNormalisedInput
39+
emailPasswordRecipe *emailpassword.Recipe
40+
thirdPartyRecipe *thirdparty.Recipe
41+
RecipeImpl tpepmodels.RecipeInterface
42+
APIImpl tpepmodels.APIInterface
43+
EmailDelivery emaildelivery.Ingredient
44+
GetEmailPasswordRecipe func() *emailpassword.Recipe
4445
}
4546

4647
var singletonInstance *Recipe
@@ -100,6 +101,10 @@ func MakeRecipe(recipeId string, appInfo supertokens.NormalisedAppinfo, config *
100101
r.emailPasswordRecipe = emailPasswordInstance
101102
}
102103

104+
r.GetEmailPasswordRecipe = func() *emailpassword.Recipe {
105+
return r.emailPasswordRecipe
106+
}
107+
103108
if len(verifiedConfig.Providers) > 0 {
104109
if thirdPartyInstance == nil {
105110
thirdPartyConfig := &tpmodels.TypeInput{

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.12.8"
24+
const VERSION = "0.12.9"
2525

2626
var (
2727
cdiSupported = []string{"2.21"}

0 commit comments

Comments
 (0)