Skip to content

Commit 4ae28ce

Browse files
Merge pull request #223 from supertokens/dashboard-user-get-change
fix: Update dashboard recipe user Get API
2 parents 26337d4 + 8ba6f51 commit 4ae28ce

File tree

21 files changed

+190
-116
lines changed

21 files changed

+190
-116
lines changed

CHANGELOG.md

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

88
## [unreleased]
99

10+
## [0.9.14] - 2022-12-26
11+
12+
- Fixes an issue in the dashboard recipe when fetching user details for passwordless users that don't have an email associated with their accounts
13+
- Updates dashboard version
14+
- Updates user GET API for dashboard recipe
15+
1016
## [0.9.13] - 2022-12-26
1117
- Adds optional `Username` to `SMTPSettings`, which can be used for SMTP login if username is different from `From.Email`.
1218

recipe/dashboard/api/userdetails/userGet.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ func UserGet(apiImplementation dashboardmodels.APIInterface, options dashboardmo
5151
}
5252
}
5353

54+
if !api.IsRecipeInitialised(recipeId) {
55+
return userGetResponse{
56+
Status: "RECIPE_NOT_INITIALISED",
57+
}, nil
58+
}
59+
5460
userForRecipeId, _ := api.GetUserForRecipeId(userId, recipeId)
5561

5662
if userForRecipeId == (dashboardmodels.UserType{}) {

recipe/dashboard/api/utils.go

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ func GetUserForRecipeId(userId string, recipeId string) (user dashboardmodels.Us
6464
userToReturn.FirstName = ""
6565
userToReturn.LastName = ""
6666
userToReturn.Email = response.Email
67-
userToReturn.ThirdParty.Id = response.ThirdParty.ID
68-
userToReturn.ThirdParty.UserId = response.ThirdParty.UserID
67+
userToReturn.ThirdParty = &dashboardmodels.ThirdParty{
68+
Id: response.ThirdParty.ID,
69+
UserId: response.ThirdParty.UserID,
70+
}
6971
}
7072

7173
if userToReturn == (dashboardmodels.UserType{}) {
@@ -77,8 +79,10 @@ func GetUserForRecipeId(userId string, recipeId string) (user dashboardmodels.Us
7779
userToReturn.FirstName = ""
7880
userToReturn.LastName = ""
7981
userToReturn.Email = tpepResponse.Email
80-
userToReturn.ThirdParty.Id = tpepResponse.ThirdParty.ID
81-
userToReturn.ThirdParty.UserId = tpepResponse.ThirdParty.UserID
82+
userToReturn.ThirdParty = &dashboardmodels.ThirdParty{
83+
Id: tpepResponse.ThirdParty.ID,
84+
UserId: tpepResponse.ThirdParty.UserID,
85+
}
8286
}
8387
}
8488
} else if recipeId == passwordless.RECIPE_ID {
@@ -121,3 +125,61 @@ func GetUserForRecipeId(userId string, recipeId string) (user dashboardmodels.Us
121125

122126
return userToReturn, recipeToReturn
123127
}
128+
129+
func IsRecipeInitialised(recipeId string) bool {
130+
isRecipeInitialised := false
131+
132+
if recipeId == emailpassword.RECIPE_ID {
133+
_, err := emailpassword.GetRecipeInstanceOrThrowError()
134+
135+
if err == nil {
136+
isRecipeInitialised = true
137+
}
138+
139+
if !isRecipeInitialised {
140+
_, err := thirdpartyemailpassword.GetRecipeInstanceOrThrowError()
141+
142+
if err == nil {
143+
isRecipeInitialised = true
144+
}
145+
}
146+
} else if recipeId == passwordless.RECIPE_ID {
147+
_, err := passwordless.GetRecipeInstanceOrThrowError()
148+
149+
if err == nil {
150+
isRecipeInitialised = true
151+
}
152+
153+
if !isRecipeInitialised {
154+
_, err := thirdpartypasswordless.GetRecipeInstanceOrThrowError()
155+
156+
if err == nil {
157+
isRecipeInitialised = true
158+
}
159+
}
160+
} else if recipeId == thirdparty.RECIPE_ID {
161+
_, err := thirdparty.GetRecipeInstanceOrThrowError()
162+
163+
if err == nil {
164+
isRecipeInitialised = true
165+
}
166+
167+
if !isRecipeInitialised {
168+
_, err := thirdpartyemailpassword.GetRecipeInstanceOrThrowError()
169+
170+
if err == nil {
171+
isRecipeInitialised = true
172+
}
173+
}
174+
175+
if !isRecipeInitialised {
176+
_, err := thirdpartypasswordless.GetRecipeInstanceOrThrowError()
177+
178+
if err == nil {
179+
isRecipeInitialised = true
180+
}
181+
}
182+
}
183+
184+
return isRecipeInitialised
185+
}

recipe/dashboard/dashboardmodels/models.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ type UserType struct {
4141
FirstName string `json:"firstName,omitempty"`
4242
LastName string `json:"lastName,omitempty"`
4343
Email string `json:"email,omitempty"`
44-
ThirdParty ThirdParty `json:"thirdParty,omitempty"`
45-
Phone string `json:"phone,omitempty"`
44+
ThirdParty *ThirdParty `json:"thirdParty,omitempty"`
45+
Phone string `json:"phoneNumber,omitempty"`
4646
}

recipe/emailpassword/config_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestDefaultConfigForEmailPasswordModule(t *testing.T) {
4646
if err != nil {
4747
t.Error(err.Error())
4848
}
49-
singletonEmailPasswordInstance, err := getRecipeInstanceOrThrowError()
49+
singletonEmailPasswordInstance, err := GetRecipeInstanceOrThrowError()
5050
if err != nil {
5151
t.Error(err.Error())
5252
}
@@ -106,7 +106,7 @@ func TestChangedConfigForEmailPasswordModule(t *testing.T) {
106106
if err != nil {
107107
t.Error(err.Error())
108108
}
109-
singletonEmailPasswordInstance, err := getRecipeInstanceOrThrowError()
109+
singletonEmailPasswordInstance, err := GetRecipeInstanceOrThrowError()
110110
if err != nil {
111111
t.Error(err.Error())
112112
}
@@ -157,7 +157,7 @@ func TestNoEmailPasswordValidatorsGivenShouldAddThem(t *testing.T) {
157157
if err != nil {
158158
t.Error(err.Error())
159159
}
160-
singletonEmailPasswordInstance, err := getRecipeInstanceOrThrowError()
160+
singletonEmailPasswordInstance, err := GetRecipeInstanceOrThrowError()
161161
if err != nil {
162162
t.Error(err.Error())
163163
}
@@ -189,7 +189,7 @@ func TestToCheckTheDefaultEmailPasswordValidators(t *testing.T) {
189189
if err != nil {
190190
t.Error(err.Error())
191191
}
192-
singletonEmailPasswordInstance, err := getRecipeInstanceOrThrowError()
192+
singletonEmailPasswordInstance, err := GetRecipeInstanceOrThrowError()
193193
if err != nil {
194194
t.Error(err.Error())
195195
}

recipe/emailpassword/main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,63 +27,63 @@ func Init(config *epmodels.TypeInput) supertokens.Recipe {
2727
}
2828

2929
func SignUpWithContext(email string, password string, userContext supertokens.UserContext) (epmodels.SignUpResponse, error) {
30-
instance, err := getRecipeInstanceOrThrowError()
30+
instance, err := GetRecipeInstanceOrThrowError()
3131
if err != nil {
3232
return epmodels.SignUpResponse{}, err
3333
}
3434
return (*instance.RecipeImpl.SignUp)(email, password, userContext)
3535
}
3636

3737
func SignInWithContext(email string, password string, userContext supertokens.UserContext) (epmodels.SignInResponse, error) {
38-
instance, err := getRecipeInstanceOrThrowError()
38+
instance, err := GetRecipeInstanceOrThrowError()
3939
if err != nil {
4040
return epmodels.SignInResponse{}, err
4141
}
4242
return (*instance.RecipeImpl.SignIn)(email, password, userContext)
4343
}
4444

4545
func GetUserByIDWithContext(userID string, userContext supertokens.UserContext) (*epmodels.User, error) {
46-
instance, err := getRecipeInstanceOrThrowError()
46+
instance, err := GetRecipeInstanceOrThrowError()
4747
if err != nil {
4848
return nil, err
4949
}
5050
return (*instance.RecipeImpl.GetUserByID)(userID, userContext)
5151
}
5252

5353
func GetUserByEmailWithContext(email string, userContext supertokens.UserContext) (*epmodels.User, error) {
54-
instance, err := getRecipeInstanceOrThrowError()
54+
instance, err := GetRecipeInstanceOrThrowError()
5555
if err != nil {
5656
return nil, err
5757
}
5858
return (*instance.RecipeImpl.GetUserByEmail)(email, userContext)
5959
}
6060

6161
func CreateResetPasswordTokenWithContext(userID string, userContext supertokens.UserContext) (epmodels.CreateResetPasswordTokenResponse, error) {
62-
instance, err := getRecipeInstanceOrThrowError()
62+
instance, err := GetRecipeInstanceOrThrowError()
6363
if err != nil {
6464
return epmodels.CreateResetPasswordTokenResponse{}, err
6565
}
6666
return (*instance.RecipeImpl.CreateResetPasswordToken)(userID, userContext)
6767
}
6868

6969
func ResetPasswordUsingTokenWithContext(token string, newPassword string, userContext supertokens.UserContext) (epmodels.ResetPasswordUsingTokenResponse, error) {
70-
instance, err := getRecipeInstanceOrThrowError()
70+
instance, err := GetRecipeInstanceOrThrowError()
7171
if err != nil {
7272
return epmodels.ResetPasswordUsingTokenResponse{}, nil
7373
}
7474
return (*instance.RecipeImpl.ResetPasswordUsingToken)(token, newPassword, userContext)
7575
}
7676

7777
func UpdateEmailOrPasswordWithContext(userId string, email *string, password *string, userContext supertokens.UserContext) (epmodels.UpdateEmailOrPasswordResponse, error) {
78-
instance, err := getRecipeInstanceOrThrowError()
78+
instance, err := GetRecipeInstanceOrThrowError()
7979
if err != nil {
8080
return epmodels.UpdateEmailOrPasswordResponse{}, nil
8181
}
8282
return (*instance.RecipeImpl.UpdateEmailOrPassword)(userId, email, password, userContext)
8383
}
8484

8585
func SendEmailWithContext(input emaildelivery.EmailType, userContext supertokens.UserContext) error {
86-
instance, err := getRecipeInstanceOrThrowError()
86+
instance, err := GetRecipeInstanceOrThrowError()
8787
if err != nil {
8888
return err
8989
}

recipe/emailpassword/recipe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func recipeInit(config *epmodels.TypeInput) supertokens.Recipe {
8686
}
8787
}
8888

89-
func getRecipeInstanceOrThrowError() (*Recipe, error) {
89+
func GetRecipeInstanceOrThrowError() (*Recipe, error) {
9090
if singletonInstance != nil {
9191
return singletonInstance, nil
9292
}

recipe/passwordless/config_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestMinimumConfigWithEmailOrPhoneContactMethod(t *testing.T) {
7777
return
7878
}
7979

80-
passwordlessRecipe, err := getRecipeInstanceOrThrowError()
80+
passwordlessRecipe, err := GetRecipeInstanceOrThrowError()
8181
assert.NoError(t, err)
8282
assert.Equal(t, "USER_INPUT_CODE_AND_MAGIC_LINK", passwordlessRecipe.Config.FlowType)
8383
}
@@ -415,7 +415,7 @@ func TestMinimumConfigWithPhoneContactMethod(t *testing.T) {
415415
return
416416
}
417417

418-
passwordlessRecipe, err := getRecipeInstanceOrThrowError()
418+
passwordlessRecipe, err := GetRecipeInstanceOrThrowError()
419419
assert.NoError(t, err)
420420
assert.Equal(t, "USER_INPUT_CODE_AND_MAGIC_LINK", passwordlessRecipe.Config.FlowType)
421421
assert.True(t, passwordlessRecipe.Config.ContactMethodPhone.Enabled)
@@ -942,7 +942,7 @@ func TestMinimumConfigWithEmailContactMethod(t *testing.T) {
942942
return
943943
}
944944

945-
passwordlessRecipe, err := getRecipeInstanceOrThrowError()
945+
passwordlessRecipe, err := GetRecipeInstanceOrThrowError()
946946
assert.NoError(t, err)
947947
assert.Equal(t, "USER_INPUT_CODE_AND_MAGIC_LINK", passwordlessRecipe.Config.FlowType)
948948
assert.True(t, passwordlessRecipe.Config.ContactMethodEmail.Enabled)

0 commit comments

Comments
 (0)