Skip to content

Commit

Permalink
Merge pull request #383 from supertokens/dashboard-no-users-fix
Browse files Browse the repository at this point in the history
fix: Fix issue of dashboard showing no user found for thirdparty users with thirdpartypasswordless
  • Loading branch information
rishabhpoddar authored Oct 19, 2023
2 parents b19c439 + ae05193 commit 178929e
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [0.16.3] - 2023-10-19

- 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

## [0.16.2] - 2023-10-17

- 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
Expand Down
37 changes: 31 additions & 6 deletions recipe/dashboard/api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func GetUserForRecipeId(userId string, recipeId string, userContext supertokens.
if recipeId == emailpassword.RECIPE_ID {
response, error := emailpassword.GetUserByID(userId, userContext)

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

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

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

if tpepError == nil {
if tpepError == nil && tpepResponse != nil {
userToReturn.Id = tpepResponse.ID
userToReturn.TimeJoined = tpepResponse.TimeJoined
userToReturn.FirstName = ""
Expand All @@ -92,10 +92,35 @@ func GetUserForRecipeId(userId string, recipeId string, userContext supertokens.
userToReturn.TenantIds = tpepResponse.TenantIds
}
}

if reflect.DeepEqual(userToReturn, dashboardmodels.UserType{}) {
tpplessResponse, tpplessError := thirdpartypasswordless.GetUserById(userId, userContext)

if tpplessError == nil && tpplessResponse != nil {
userToReturn.Id = tpplessResponse.ID
userToReturn.TimeJoined = tpplessResponse.TimeJoined
userToReturn.FirstName = ""
userToReturn.LastName = ""

if tpplessResponse.Email != nil {
userToReturn.Email = *tpplessResponse.Email
}

if tpplessResponse.PhoneNumber != nil {
userToReturn.Phone = *tpplessResponse.PhoneNumber
}

userToReturn.ThirdParty = &dashboardmodels.ThirdParty{
Id: tpplessResponse.ThirdParty.ID,
UserId: tpplessResponse.ThirdParty.UserID,
}
userToReturn.TenantIds = tpplessResponse.TenantIds
}
}
} else if recipeId == passwordless.RECIPE_ID {
response, error := passwordless.GetUserByID(userId, userContext)

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

if tppError == nil {
if tppError == nil && tppResponse != nil {
userToReturn.Id = tppResponse.ID
userToReturn.TimeJoined = tppResponse.TimeJoined
userToReturn.FirstName = ""
Expand Down
80 changes: 80 additions & 0 deletions recipe/dashboard/userGet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ package dashboard

import (
"encoding/json"
"github.com/supertokens/supertokens-golang/recipe/dashboard/api"
"github.com/supertokens/supertokens-golang/recipe/dashboard/api/userdetails"
"github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels"
"github.com/supertokens/supertokens-golang/recipe/session"
"github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels"
"github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless"
"github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/tplmodels"
"io"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -79,3 +85,77 @@ func TestThatUserGetReturnsTenantIDsCorrectly(t *testing.T) {
assert.True(t, len(response.User.TenantIds) > 0)
assert.Equal(t, response.User.TenantIds[0], "public")
}

func TestThatUserGetReturnsValidUserForThirdPartyUserWhenUsingThirdPartyPasswordless(t *testing.T) {
config := supertokens.TypeInput{
Supertokens: &supertokens.ConnectionInfo{
ConnectionURI: "http://localhost:8080",
},
AppInfo: supertokens.AppInfo{
APIDomain: "api.supertokens.io",
AppName: "SuperTokens",
WebsiteDomain: "supertokens.io",
},
RecipeList: []supertokens.Recipe{
thirdpartypasswordless.Init(tplmodels.TypeInput{
FlowType: "USER_INPUT_CODE_AND_MAGIC_LINK",
ContactMethodEmailOrPhone: plessmodels.ContactMethodEmailOrPhoneConfig{
Enabled: true,
},
Providers: []tpmodels.ProviderInput{
thirdpartypasswordless.SigninupCustomProvider1,
},
}),
Init(&dashboardmodels.TypeInput{
ApiKey: "testapikey",
}),
session.Init(nil),
},
}

BeforeEach()
unittesting.StartUpST("localhost", "8080")
defer AfterEach()
err := supertokens.Init(config)
if err != nil {
t.Error(err.Error())
}

mux := http.NewServeMux()
testServer := httptest.NewServer(supertokens.Middleware(mux))
defer testServer.Close()

_, err = unittesting.SigninupCustomRequest(testServer.URL, "[email protected]", "testPass0")

if err != nil {
t.Error(err.Error())
}

req, err := http.NewRequest(http.MethodGet, testServer.URL+"/auth/dashboard/api/users?limit=10", strings.NewReader(`{}`))
req.Header.Set("Authorization", "Bearer testapikey")
res, err := http.DefaultClient.Do(req)

if err != nil {
t.Error(err.Error())
}

var listResponse api.UsersGetResponse
body, _ := io.ReadAll(res.Body)
json.Unmarshal(body, &listResponse)

user := listResponse.Users[0].User

req, err = http.NewRequest(http.MethodGet, testServer.URL+"/auth/dashboard/api/user?userId="+user.Id+"&recipeId=thirdparty", strings.NewReader(`{}`))
req.Header.Set("Authorization", "Bearer testapikey")
res, err = http.DefaultClient.Do(req)

if err != nil {
t.Error(err.Error())
}

var response userdetails.UserGetResponse
body, _ = io.ReadAll(res.Body)
json.Unmarshal(body, &response)

assert.Equal(t, response.Status, "OK")
}
10 changes: 5 additions & 5 deletions recipe/thirdpartypasswordless/signinupFeature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func TestWithThirdPartyPasswordlessMinimumConfigForThirdpartyModule(t *testing.T
Enabled: true,
},
Providers: []tpmodels.ProviderInput{
signinupCustomProvider1,
SigninupCustomProvider1,
},
}),
},
Expand Down Expand Up @@ -540,7 +540,7 @@ func TestWithThirdPartyPasswordlessThirdPartyProviderDoesNotExistInConfig(t *tes
Enabled: true,
},
Providers: []tpmodels.ProviderInput{
signinupCustomProvider1,
SigninupCustomProvider1,
},
}),
},
Expand Down Expand Up @@ -788,7 +788,7 @@ func TestWithThirdPartyPasswordlessInvalidPostParamsForThirdPartyModule(t *testi
Enabled: true,
},
Providers: []tpmodels.ProviderInput{
signinupCustomProvider1,
SigninupCustomProvider1,
},
}),
},
Expand Down Expand Up @@ -888,7 +888,7 @@ func TestWithThirdPartyPasswordlessGetUserByIdWhenUserDoesNotExist(t *testing.T)
Enabled: true,
},
Providers: []tpmodels.ProviderInput{
signinupCustomProvider1,
SigninupCustomProvider1,
},
}),
},
Expand Down Expand Up @@ -992,7 +992,7 @@ func TestGetUserByThirdPartyInfoWhenUserDoesNotExist(t *testing.T) {
Enabled: true,
},
Providers: []tpmodels.ProviderInput{
signinupCustomProvider1,
SigninupCustomProvider1,
},
}),
},
Expand Down
8 changes: 4 additions & 4 deletions recipe/thirdpartypasswordless/signoutFeature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestTheDefaultRouteAndItShouldRevokeTheSession(t *testing.T) {
Enabled: true,
},
Providers: []tpmodels.ProviderInput{
signinupCustomProvider1,
SigninupCustomProvider1,
},
}),
},
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestDisablingDefaultRouteAndCallingTheAPIReturns404(t *testing.T) {
},
},
Providers: []tpmodels.ProviderInput{
signinupCustomProvider1,
SigninupCustomProvider1,
},
}),
},
Expand Down Expand Up @@ -246,7 +246,7 @@ func TestCallingAPIWithoutSessionShouldReturnOk(t *testing.T) {
Enabled: true,
},
Providers: []tpmodels.ProviderInput{
signinupCustomProvider1,
SigninupCustomProvider1,
},
}),
},
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestThatSignoutAPIreturnsTryRefreshTokenRefreshSessionAndSignoutShouldRetur
Enabled: true,
},
Providers: []tpmodels.ProviderInput{
signinupCustomProvider1,
SigninupCustomProvider1,
},
}),
},
Expand Down
2 changes: 1 addition & 1 deletion recipe/thirdpartypasswordless/testingUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var mockThirdPartyProvider2 = tpmodels.ProviderInput{
},
}

var signinupCustomProvider1 = tpmodels.ProviderInput{
var SigninupCustomProvider1 = tpmodels.ProviderInput{
Config: tpmodels.ProviderConfig{
ThirdPartyId: "custom",
Clients: []tpmodels.ProviderClientConfig{
Expand Down
2 changes: 1 addition & 1 deletion supertokens/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
)

// VERSION current version of the lib
const VERSION = "0.16.2"
const VERSION = "0.16.3"

var (
cdiSupported = []string{"3.0"}
Expand Down

0 comments on commit 178929e

Please sign in to comment.