Skip to content

Commit 178929e

Browse files
Merge pull request #383 from supertokens/dashboard-no-users-fix
fix: Fix issue of dashboard showing no user found for thirdparty users with thirdpartypasswordless
2 parents b19c439 + ae05193 commit 178929e

File tree

7 files changed

+126
-17
lines changed

7 files changed

+126
-17
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.16.3] - 2023-10-19
11+
12+
- Fixes an issue where trying to view details of a third party user would show an error for the user not being found when using the thirdpartypasswordless recipe
13+
1014
## [0.16.2] - 2023-10-17
1115

1216
- Fixes an issue where tenant ids returned for a user from the user get API of the dashboard recipe would always be nil for thirdpartyemailpassword and thirdpartypasswordless recipes

recipe/dashboard/api/utils.go

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func GetUserForRecipeId(userId string, recipeId string, userContext supertokens.
3535
if recipeId == emailpassword.RECIPE_ID {
3636
response, error := emailpassword.GetUserByID(userId, userContext)
3737

38-
if error == nil {
38+
if error == nil && response != nil {
3939
userToReturn.Id = response.ID
4040
userToReturn.TimeJoined = response.TimeJoined
4141
userToReturn.FirstName = ""
@@ -49,7 +49,7 @@ func GetUserForRecipeId(userId string, recipeId string, userContext supertokens.
4949
if reflect.DeepEqual(userToReturn, dashboardmodels.UserType{}) {
5050
tpepResponse, tpepError := thirdpartyemailpassword.GetUserById(userId, userContext)
5151

52-
if tpepError == nil {
52+
if tpepError == nil && tpepResponse != nil {
5353
userToReturn.Id = tpepResponse.ID
5454
userToReturn.TimeJoined = tpepResponse.TimeJoined
5555
userToReturn.FirstName = ""
@@ -63,7 +63,7 @@ func GetUserForRecipeId(userId string, recipeId string, userContext supertokens.
6363
} else if recipeId == thirdparty.RECIPE_ID {
6464
response, error := thirdparty.GetUserByID(userId, userContext)
6565

66-
if error == nil {
66+
if error == nil && response != nil {
6767
userToReturn.Id = response.ID
6868
userToReturn.TimeJoined = response.TimeJoined
6969
userToReturn.FirstName = ""
@@ -79,7 +79,7 @@ func GetUserForRecipeId(userId string, recipeId string, userContext supertokens.
7979
if reflect.DeepEqual(userToReturn, dashboardmodels.UserType{}) {
8080
tpepResponse, tpepError := thirdpartyemailpassword.GetUserById(userId, userContext)
8181

82-
if tpepError == nil {
82+
if tpepError == nil && tpepResponse != nil {
8383
userToReturn.Id = tpepResponse.ID
8484
userToReturn.TimeJoined = tpepResponse.TimeJoined
8585
userToReturn.FirstName = ""
@@ -92,10 +92,35 @@ func GetUserForRecipeId(userId string, recipeId string, userContext supertokens.
9292
userToReturn.TenantIds = tpepResponse.TenantIds
9393
}
9494
}
95+
96+
if reflect.DeepEqual(userToReturn, dashboardmodels.UserType{}) {
97+
tpplessResponse, tpplessError := thirdpartypasswordless.GetUserById(userId, userContext)
98+
99+
if tpplessError == nil && tpplessResponse != nil {
100+
userToReturn.Id = tpplessResponse.ID
101+
userToReturn.TimeJoined = tpplessResponse.TimeJoined
102+
userToReturn.FirstName = ""
103+
userToReturn.LastName = ""
104+
105+
if tpplessResponse.Email != nil {
106+
userToReturn.Email = *tpplessResponse.Email
107+
}
108+
109+
if tpplessResponse.PhoneNumber != nil {
110+
userToReturn.Phone = *tpplessResponse.PhoneNumber
111+
}
112+
113+
userToReturn.ThirdParty = &dashboardmodels.ThirdParty{
114+
Id: tpplessResponse.ThirdParty.ID,
115+
UserId: tpplessResponse.ThirdParty.UserID,
116+
}
117+
userToReturn.TenantIds = tpplessResponse.TenantIds
118+
}
119+
}
95120
} else if recipeId == passwordless.RECIPE_ID {
96121
response, error := passwordless.GetUserByID(userId, userContext)
97122

98-
if error == nil {
123+
if error == nil && response != nil {
99124
userToReturn.Id = response.ID
100125
userToReturn.TimeJoined = response.TimeJoined
101126
userToReturn.FirstName = ""
@@ -115,7 +140,7 @@ func GetUserForRecipeId(userId string, recipeId string, userContext supertokens.
115140
if reflect.DeepEqual(userToReturn, dashboardmodels.UserType{}) {
116141
tppResponse, tppError := thirdpartypasswordless.GetUserByID(userId, userContext)
117142

118-
if tppError == nil {
143+
if tppError == nil && tppResponse != nil {
119144
userToReturn.Id = tppResponse.ID
120145
userToReturn.TimeJoined = tppResponse.TimeJoined
121146
userToReturn.FirstName = ""

recipe/dashboard/userGet_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ package dashboard
22

33
import (
44
"encoding/json"
5+
"github.com/supertokens/supertokens-golang/recipe/dashboard/api"
56
"github.com/supertokens/supertokens-golang/recipe/dashboard/api/userdetails"
7+
"github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels"
8+
"github.com/supertokens/supertokens-golang/recipe/session"
9+
"github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels"
10+
"github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless"
11+
"github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/tplmodels"
612
"io"
713
"net/http"
814
"net/http/httptest"
@@ -79,3 +85,77 @@ func TestThatUserGetReturnsTenantIDsCorrectly(t *testing.T) {
7985
assert.True(t, len(response.User.TenantIds) > 0)
8086
assert.Equal(t, response.User.TenantIds[0], "public")
8187
}
88+
89+
func TestThatUserGetReturnsValidUserForThirdPartyUserWhenUsingThirdPartyPasswordless(t *testing.T) {
90+
config := supertokens.TypeInput{
91+
Supertokens: &supertokens.ConnectionInfo{
92+
ConnectionURI: "http://localhost:8080",
93+
},
94+
AppInfo: supertokens.AppInfo{
95+
APIDomain: "api.supertokens.io",
96+
AppName: "SuperTokens",
97+
WebsiteDomain: "supertokens.io",
98+
},
99+
RecipeList: []supertokens.Recipe{
100+
thirdpartypasswordless.Init(tplmodels.TypeInput{
101+
FlowType: "USER_INPUT_CODE_AND_MAGIC_LINK",
102+
ContactMethodEmailOrPhone: plessmodels.ContactMethodEmailOrPhoneConfig{
103+
Enabled: true,
104+
},
105+
Providers: []tpmodels.ProviderInput{
106+
thirdpartypasswordless.SigninupCustomProvider1,
107+
},
108+
}),
109+
Init(&dashboardmodels.TypeInput{
110+
ApiKey: "testapikey",
111+
}),
112+
session.Init(nil),
113+
},
114+
}
115+
116+
BeforeEach()
117+
unittesting.StartUpST("localhost", "8080")
118+
defer AfterEach()
119+
err := supertokens.Init(config)
120+
if err != nil {
121+
t.Error(err.Error())
122+
}
123+
124+
mux := http.NewServeMux()
125+
testServer := httptest.NewServer(supertokens.Middleware(mux))
126+
defer testServer.Close()
127+
128+
_, err = unittesting.SigninupCustomRequest(testServer.URL, "test@gmail.com", "testPass0")
129+
130+
if err != nil {
131+
t.Error(err.Error())
132+
}
133+
134+
req, err := http.NewRequest(http.MethodGet, testServer.URL+"/auth/dashboard/api/users?limit=10", strings.NewReader(`{}`))
135+
req.Header.Set("Authorization", "Bearer testapikey")
136+
res, err := http.DefaultClient.Do(req)
137+
138+
if err != nil {
139+
t.Error(err.Error())
140+
}
141+
142+
var listResponse api.UsersGetResponse
143+
body, _ := io.ReadAll(res.Body)
144+
json.Unmarshal(body, &listResponse)
145+
146+
user := listResponse.Users[0].User
147+
148+
req, err = http.NewRequest(http.MethodGet, testServer.URL+"/auth/dashboard/api/user?userId="+user.Id+"&recipeId=thirdparty", strings.NewReader(`{}`))
149+
req.Header.Set("Authorization", "Bearer testapikey")
150+
res, err = http.DefaultClient.Do(req)
151+
152+
if err != nil {
153+
t.Error(err.Error())
154+
}
155+
156+
var response userdetails.UserGetResponse
157+
body, _ = io.ReadAll(res.Body)
158+
json.Unmarshal(body, &response)
159+
160+
assert.Equal(t, response.Status, "OK")
161+
}

recipe/thirdpartypasswordless/signinupFeature_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ func TestWithThirdPartyPasswordlessMinimumConfigForThirdpartyModule(t *testing.T
321321
Enabled: true,
322322
},
323323
Providers: []tpmodels.ProviderInput{
324-
signinupCustomProvider1,
324+
SigninupCustomProvider1,
325325
},
326326
}),
327327
},
@@ -540,7 +540,7 @@ func TestWithThirdPartyPasswordlessThirdPartyProviderDoesNotExistInConfig(t *tes
540540
Enabled: true,
541541
},
542542
Providers: []tpmodels.ProviderInput{
543-
signinupCustomProvider1,
543+
SigninupCustomProvider1,
544544
},
545545
}),
546546
},
@@ -788,7 +788,7 @@ func TestWithThirdPartyPasswordlessInvalidPostParamsForThirdPartyModule(t *testi
788788
Enabled: true,
789789
},
790790
Providers: []tpmodels.ProviderInput{
791-
signinupCustomProvider1,
791+
SigninupCustomProvider1,
792792
},
793793
}),
794794
},
@@ -888,7 +888,7 @@ func TestWithThirdPartyPasswordlessGetUserByIdWhenUserDoesNotExist(t *testing.T)
888888
Enabled: true,
889889
},
890890
Providers: []tpmodels.ProviderInput{
891-
signinupCustomProvider1,
891+
SigninupCustomProvider1,
892892
},
893893
}),
894894
},
@@ -992,7 +992,7 @@ func TestGetUserByThirdPartyInfoWhenUserDoesNotExist(t *testing.T) {
992992
Enabled: true,
993993
},
994994
Providers: []tpmodels.ProviderInput{
995-
signinupCustomProvider1,
995+
SigninupCustomProvider1,
996996
},
997997
}),
998998
},

recipe/thirdpartypasswordless/signoutFeature_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestTheDefaultRouteAndItShouldRevokeTheSession(t *testing.T) {
5959
Enabled: true,
6060
},
6161
Providers: []tpmodels.ProviderInput{
62-
signinupCustomProvider1,
62+
SigninupCustomProvider1,
6363
},
6464
}),
6565
},
@@ -179,7 +179,7 @@ func TestDisablingDefaultRouteAndCallingTheAPIReturns404(t *testing.T) {
179179
},
180180
},
181181
Providers: []tpmodels.ProviderInput{
182-
signinupCustomProvider1,
182+
SigninupCustomProvider1,
183183
},
184184
}),
185185
},
@@ -246,7 +246,7 @@ func TestCallingAPIWithoutSessionShouldReturnOk(t *testing.T) {
246246
Enabled: true,
247247
},
248248
Providers: []tpmodels.ProviderInput{
249-
signinupCustomProvider1,
249+
SigninupCustomProvider1,
250250
},
251251
}),
252252
},
@@ -312,7 +312,7 @@ func TestThatSignoutAPIreturnsTryRefreshTokenRefreshSessionAndSignoutShouldRetur
312312
Enabled: true,
313313
},
314314
Providers: []tpmodels.ProviderInput{
315-
signinupCustomProvider1,
315+
SigninupCustomProvider1,
316316
},
317317
}),
318318
},

recipe/thirdpartypasswordless/testingUtils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ var mockThirdPartyProvider2 = tpmodels.ProviderInput{
9696
},
9797
}
9898

99-
var signinupCustomProvider1 = tpmodels.ProviderInput{
99+
var SigninupCustomProvider1 = tpmodels.ProviderInput{
100100
Config: tpmodels.ProviderConfig{
101101
ThirdPartyId: "custom",
102102
Clients: []tpmodels.ProviderClientConfig{

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

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

0 commit comments

Comments
 (0)